Javascript 过重XMLHttpRequest会导致负载故障
我试图统计ajax调用的数量。我想这样做,直到所有ajax调用返回。 我编写了以下代码:Javascript 过重XMLHttpRequest会导致负载故障,javascript,php,jquery,ajax,selenium,Javascript,Php,Jquery,Ajax,Selenium,我试图统计ajax调用的数量。我想这样做,直到所有ajax调用返回。 我编写了以下代码: var xmlreqc=XMLHttpRequest; XMLHttpRequest = function() { this.xhr = new xmlreqc(); return this; }; XMLHttpRequest.prototype.open = function (method, url, async) { return this.xhr.open(method, ur
var xmlreqc=XMLHttpRequest;
XMLHttpRequest = function() {
this.xhr = new xmlreqc();
return this;
};
XMLHttpRequest.prototype.open = function (method, url, async) {
return this.xhr.open(method, url, async); //send it on
};
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
this.xhr.setRequestHeader(header, value);
};
XMLHttpRequest.prototype.getAllResponseHeaders = function() {
console.log( this.xhr.getAllResponseHeaders());
return this.xhr.getAllResponseHeaders();
};
XMLHttpRequest.prototype.send = function(postBody) {
// steal the request
nRemAjax++;
// do the real transmission
var myXHR = this;
this.xhr.onreadystatechange = function() { myXHR.onreadystatechangefunction();};
this.xhr.send(postBody);
};
XMLHttpRequest.prototype.onreadystatechangefunction = function()
{
try {
this.readyState = this.xhr.readyState;
this.responseText = this.xhr.responseText;
console.log(this.xhr.responseText); // this line log json data though
this.responseXML = this.xhr.responseXML;
this.status = this.xhr.status;
this.statusText = this.xhr.statusText;
}
catch(e){
}
if (this.onreadystatechange)
this.onreadystatechange();
//do my logging
if (this.xhr.readyState == 4)
{
nRemAjax--;
// only when done steal the response
consoleLog("I'm finished");
}
};
我已经将上述代码注入到浏览器中
这适用于大多数网站,除了
由于某些原因,页面加载时未正确加载区域/状态字段
我发现区域/字段中填充了JSON数据,这些数据是作为ajax调用的响应发送的
请注意,我正在头部添加此脚本。为什么需要重新定义所有方法?所有你需要它来关闭,比如说,open(),然后你可以在里面添加这个事件,允许你现在设置的所有日志…感谢dandavis的快速响应。你能再解释一下吗?谢谢