2018-03-15

2018-03-20  本文已影响0人  逮呆

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();

}

上一篇下一篇

猜你喜欢

热点阅读