Ajax 同步、异步
一、XMLHttpRequest (XHR)对象

发送请求:
open(method,url,async)
send(string)

获取响应:
responseText:获取字符串形式的响应数据
responseXML:获取XML形式的响应数据
status和statusText : 以数字和文本形式返回HTTP状态码
getAllResponseHeader() :获取所有的响应报头
getResponseHeader() :查询响应中的某个字段的值
readyState属性:
0:请求未初始化 open还没调用
1:服务连接已建立 open已经调用
2:请求已接收 (接收到头信息了)
3:请求处理中 (已经接收到响应主题)
4:请求已完成 且响应已就绪

二、HTTP 请求
HTTP是一种无状态协议
HTTP是计算机通过网络进行通信的规则

解析:1. HTTP请求方法或动作 比如GET/POST请求
2. 正在请求的URL
3. 请求头,包含一些客户环境信息 身份验证信息等
4. 请求体 也就是请求正文 请求正文中可以包含客户提交的查询字符串信息 表单信息等




三、JSON

json 与 xml比较:

json语法规则:


json 解析:
eval 和 JSON.parse


eval 比较危险
JSON.parse 会检验json格式 返回错误
json格式化:

jQuery中 Ajax
1. jQuery.ajax([settings])


跨域



处理跨域:
1> 代理
2> JSONP

局限:不支持POST方式 支持GET方式
3>XHR2

网友评论