ajax中的小知识点
来源:互联网 发布:哈尔斯保温杯价格 知乎 编辑:程序博客网 时间:2024/05/06 23:02
1. GET: 一次请求,由于GET数据可以缓存
最为常见的HTTP请求,普通上网浏览页面就是GET。GET方式的参数请求直接跟在URL后,以问号开始。(JS中用window.location.search获得)。参数可以用encodeURIComponent进行编码,使用方式:
var EnParam = encodeURIComponent(param);
URL只支持大约2K的长度,即2048字符数;使用GET进行AJAX请求时候会缓存导致出现的页面不是正确的,一般方法加random参数值;ajax.send(null)。
<form method="get" action="a.asp?b=b">跟<form method="get" action="a.asp">是一样的,也就是说,method为get时action页面后边带的参数列表会被忽视;而<form method="post" action="a.asp?b=b">跟<form method="post" action="a.asp">是不一样的。
GET /?username=%E5%BC%A0%E4%B8%89 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
Host: localhost
Connection: Keep-Alive
2. POST: 两次请求(请求头,数据体), POST比GET更安全
向服务器提交数据用到。
需要将form表单中的值先取出转换成字符串,用&符号连接,(同GET传参数一样);提交数据量2GB ;使用ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'),处理提交的字符串;ajax.send(strings),这个strings表示form中需要提交的内容,例如a=1&b=2类似这样的字符串。
POST 方式:
POST / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
Host: localhost
Content-Length: 28
Connection: Keep-Alive
- ajax中的小知识点
- java中的小知识点
- 线程中的小知识点
- javascript中的小知识点
- 工作中的小知识点
- spring中的小知识点
- js中的小知识点
- OC中的小知识点
- Spring中的小知识点
- ajax中的小细节
- JSP学习中的小知识点
- Javascript 中的小知识点整理
- multisim软件中的小知识点
- Java中的小知识点杂烩
- delphi7学习中的小知识点
- 编程中的一些小知识点
- C中的几个小知识点
- iOS中的一些小知识点
- 算法导论排序算法之归并排序(六)
- MICRO2440落跑之MDK3.4下调试流水灯
- JComboBox 组合框条目渲染(JComboBox添加对象选项)
- Matlab中cov函数的算法
- MAC自动连接wifi
- ajax中的小知识点
- 构造函数调用虚函数
- Embedded Systems Memory Types
- Android实战之HttpClient
- Singleton
- Magento: The Time of report base on configuration Timezone
- 2393 Yogurt Factory
- 判断单链表是否存在环,判断两个链表是否相交问题详解(转载)
- platform的probe函数是何时被调用的