我希望通过以下方法处理所有Ajax请求:
XMLHttpRequest.prototype.send=function(body){
var myResponse='myResponse';
Object.defineProperty(this,'responseText',{
get:function(){
return res
}
});
Object.defineProperty(this,'readyState',{
get:function(){
return 4
}
});
Object.defineProperty(this,'status',{
get:function(){
return 200
}
});
this.onreadystatechange();
};
在输出中,responseText和readyState成功实现了我想要的结果。但是Chrome给了我这个错误:
Uncaught InvalidStateError: Failed to read the 'status' property from 'XMLHttpRequest': the object's state must not be OPENED.
我知道我需要将readyState设置为200,这样网页的其他部分就可以正常运行。但我不知道怎么能做到......任何建议都将不胜感激!