ajax实现

来源:互联网 发布:苹果电脑软件卡死了 编辑:程序博客网 时间:2024/05/16 19:10

function getXmlhttp(){

var xmlHttp=null;

try{

xmlHttp=new XMLHttpRequest();

}catch(e){

try{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch(e){

try{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}catch(e){

alert("   ");

}

}

}

}

/*url——url;method(post/get);con(true(异步)|false(同步));parameter(参数)

function Ajax(url,methodtype,con,parameter,functionName,obj){

var xmlHttp=getXmlhttp();

if(xmlhttp.onreadyState==4){

functionName(xmlhttp,obj);

};

xmlhttp.open(methodtype,url,con);

xmlhttp.send(parameter);

}