Joh*_*han 5 javascript ajax jquery xmlhttprequest
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, uri, async, user, pass) {
this.addEventListener("readystatechange", function(event) {
if(this.readyState == 4){
var self = this;
var response = {
method: method,
uri: uri,
responseText: self.responseText
};
console.log(response);
} else {
console.log(this.readyState);
}
}, false);
open.call(this, method, uri, async, user, pass);
};
Run Code Online (Sandbox Code Playgroud)
我正在尝试在发送 XHR 之前收听它们。同样的事情也给jQuery的beforeSend的$.ajax方法。
我的目标是在发送之前监听所有 XHR。我想最接近的事情是检查上面是否this.readyState === 1?
上面的代码是否会因为我使用原型而导致任何像 jQuery 这样的 ajax 库发生故障XMLHttpRequest?
我正在尝试在发送 XHR 之前收听它们。
然后尝试欺骗send()方法,而不是方法open()。
上面的代码是否会因为我在 XMLHttpRequest 上使用原型而导致像 jQuery 这样的任何 ajax 库发生故障?
不,不是真的。仅有的,
XMLHttpRequest(特别是 IE)XMLHttpRequest对象(或不支持访问或修改其原型),甚至会失败undefined)。要 100% 确定,请使用return open.apply(this, arguments);.| 归档时间: |
|
| 查看次数: |
9619 次 |
| 最近记录: |