/*1创建xhr对象*/
function createXhr() {
var xhr = null;
if (XMLHttpRequest) {
xhr = new XMLHttpRequest();
}else{
//兼容IE6以前的老IE
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xhr;
}
function ajax(info) {
var xhr=createXhr();
var type,async;
type=info.type=="post"?"post":"get";
async=info.async=="true"?"true":"false";
xhr.open(type,info.url,async);
if (type == "post") {
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
xhr.onreadystatechange=function () {
if(xhr.readyState==4){
if(xhr.status==200){
info.success(xhr.responseText)
}else{
info.error();
}
}
}
xhr.send(info.data);
}