2018-03-15
AJAX基本框架
function Ajax(url,funSucc,funFaild){
var request = getAjax();
if(request){
request.open("GET",url,true);
//发送请求
request.send(null);
//接受返回
request.onreadystatechange=function(){
if(request.readyState==4){
if(request.status==200)
funSucc(request.responseText);
else{
if(funFaild)
funFaild(request.status,request.responseText);
}
}
};
}else{
alert("Sorry,your browser doesn't support XMLHttpRequest");
}
}
function getAjax(){
if(typeof window.XMLHttpRequest=="undefined")
XMLHttpRequest=function(){
try{
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
}catch(e){}
try{
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
}catch(e){}
try{
return new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){}
return false;
}
return new XMLHttpRequest();
}