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);
};
我正在尝试在发送 XHR 之前收听它们.$.ajax 方法中类似于 jQuery 的 beforeSend 方法.
I am trying to listen for XHR before they are being sent. Something similar to jQuery's beforeSend in the $.ajax method.
我的目标是在发送所有 XHR 之前监听它们.我想最接近的方法是检查上面是否 this.readyState === 1?
My goal is to listen for all XHR's before they are being sent. I suppose the closest thing would be to check above if this.readyState === 1?
上面的代码是否会因为我在 XMLHttpRequest 上使用原型而导致任何 ajax 库(如 jQuery)出现故障?
Would the code above cause any ajax libraries like jQuery to malfunction because I use prototype on XMLHttpRequest?
我正在尝试在发送 XHR 之前监听它们.
I am trying to listen for XHR before they are being sent.
然后尝试欺骗 send() 方法,而不是 open() 方法.
Then try to spoof the send() method, not the open() one.
上面的代码是否会因为我在 XMLHttpRequest 上使用原型而导致任何 ajax 库(如 jQuery)出现故障?
Would the code above cause any ajax libraries like jQuery to malfunction because I use prototype on XMLHttpRequest?
不,不是真的.只是,
XMLHttpRequest(尤其是 IE)的情况下它不起作用XMLHttpRequest 对象(或不支持访问或修改其原型),甚至会失败undefined).为 100% 确定,请使用 return open.apply(this, arguments);.XMLHttpRequest (particularly IE)XMLHttpRequest object (or does not support accessing or modifying its prototype)undefined). To be 100% sure, use return open.apply(this, arguments);.这篇关于自定义 XMLHttpRequest.prototype.open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
NETWORK_ERROR:XMLHttpRequest 异常 101NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 异常 101)
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)