function goAjax(url,method,param,callBack)
{
var xmlHttp=null;
if(window.xmlHttpRequest)
{
xmlHttp=new XmlHttpRequest();
}else{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(method=="get"||method=="GET")
{
if(param.length>0)
{
url=url+"?"+param;
}
xmlHttp.open("get",url,true);
xmlHttp.setRequestHeader("If-Modified-Since","0");//不缓存
xmlHttp.send(null);
}else{
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("If-Modified-Since","0");//不缓存
xmlHttp.send(param);
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.status==200&&xmlHttp.readyState==4)
{
callBack(xmlHttp. reponseText);
}else{
alert(xmlHttp.statusText);
}
}
}
手写ajax的get与post函数
最新推荐文章于 2024-02-08 10:43:46 发布