封装一个简单ajax

function getAjax(url,funSucc,funFail){

//声明变量

var xhr=new XMLHttpRequest();

url=url+"?"+new Date().getTime()//解决IE缓存问题,不能实时删除添加

//启动

xhr.open("get",url,true);

//发送

xhr.send(null);

//接受

xhr.onreadystatechange=function (){

if (xhr.readyState==4){

//完成

if (xhr.status==200){

funSucc(xhr.responseText);//函数

}else{

if (funFail){//判断是否有第三个参数

funFail(xhr.statusText);//函数

}

}

}

}

}

你可能感兴趣的:(封装一个简单ajax)