原生ajax封装,包含post、method方式
xhr = = = ActiveXObject('Microsoft.XMLHTTP'
(method == 'get' &&+= '?' +
xhr.open(method,</span><span style="color: #0000ff;">true</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">if</span> (method == 'get'<span style="color: #000000;">) {
xhr.send();</span><span style="color: #008000;">//</span><span style="color: #008000;">get,发送时空的</span>
} <span style="color: #0000ff;">else</span><span style="color: #000000;"> {
xhr.setRequestHeader(</span>'content-type','application/x-www-form-urlencoded');<span style="color: #008000;">//</span><span style="color: #008000;">设置请求头</span>
xhr.send(data);<span style="color: #008000;">//</span><span style="color: #008000;">发送里,放数据</span>
<span style="color: #000000;"> }
xhr.onreadystatechange </span>= <span style="color: #0000ff;">function</span><span style="color: #000000;">() {
</span><span style="color: #0000ff;">if</span> ( xhr.readyState == 4<span style="color: #000000;"> ) {
</span><span style="color: #0000ff;">if</span> ( xhr.status == 200<span style="color: #000000;"> ) {
success </span>&&<span style="color: #000000;"> success(xhr.responseText);
} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
alert(</span>'出错了,Err:' +<span style="color: #000000;"> xhr.status);
}
}
}
}