我有一个运行良好但不回调 onreadystatechange 函数的 ajax oop 脚本。这是代码=>
function AjaxConstruct(method,file,params){
this.method = method;
this.file = file;
this.params = params;
this.http = false;
}
AjaxConstruct.prototype.ajax = function(){
if (window.XMLHttpRequest){
this.http = new XMLHttpRequest();
} else {
this.http = new ActiveXObject("Microsoft.XMLHTTP");
}
if (this.http){
this.http.open(this.method,this.file,true);
if (this.method==="POST"){
this.http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
this.http.send(this.params);
this.http.onreadystatechange = function(){
if (this.http.readyState==4 && this.http.status==200){
alert("yeah");
}
};
}
};
它不回调onreadystatechange匿名函数,如何解决?谢谢 :)
像这样调用方法=>
var ajax = new AjaxConstruct("POST","filename","params");
ajax.ajax();
但没有调用 onreadystatechange :(