function Ajax(){
//第一步:创建xhr对象
//根据实际情况,通过不同方式创建xhr
var xhr=null;
if (window.XMLHttpRequest) {
xhr=new XMLHttpRequest();
}else{
xhr=new ActiveXObject('Microsoft.XMLHttp')
}
//第二步:开始监听
//创建完 xhr对象后,它的工作就是 开始监听
//下面这个函数里 就2个if判断句
xhr.onreadystatechange=function (){
if (xhr.readyState == 4) {
if(xhr.status == 200) {
callback(xhr.responseText);
}else{
console.log('error');
}
}
}
//第三步:对发送过来的请求(get、post)给出回应……
method=method.toUpperCase();
if (method=='GET') {
var date=new Date(),
timer=date.getTime();
xhr.open(method, url+'?'+data+'&timer'+time, flag);
xhr.send();
}else {
xhr.open(method,url,flag);
xhr.setRequestHeader('Content-type','application//x-www-form-urlencoded');
xhr.send(data);
}
}