标签:
var request=null;
if(window.XMLHttpRequest){
try{
request=new XMLHttpRequest();
}catch(e){
request=null;
}
}else if(window.ActiveXObject){
try{
request=new ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
request=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
request=null;
}
}
}创建XMLHttpRequest对象后,换成设定处理请求的函数,然后开启请求。AjaxRequest.prototype.send=function(type,url,handler,postDataType,postData){
if(this.request!=null){
//kill the previous request
this.request.abort();
try{
this.request.onreadystatechange=handler; //自定义的处理器函数
this.request.open(type,url,true);
if(type.toLowerCase()=="get"){ //发送get请求
this.request.send(null);
}else{ //发送post请求
this.request.setRequestHeader("Content-Type",postDataType);
this.request.send(postData);
}
}catch(e){
alert("Ajax error communicating with the server.\n"+"Details:"+e);
}
}
}
var ajaxReq=new AjaxRequest();
ajaxReq.send("GET","movies.xml",handleRequest);标签:
原文地址:http://blog.csdn.net/u012755393/article/details/51367275