I want to immediately reject all AJAX requests depending on a variable. I understand how to hook the XMLHttpRequest but not sure how to reject it.
(function(open) {
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
this.addEventListener("readystatechange", function() {
if(this.readyState === 1){
// stop all ajax attempts if we're disconnected
if(!self.isConnected){
console.log('rejecting')
// reject here
this.abort(); // ???
}
}
}, false);
open.call(this, method, url, async, user, pass);
};
})(XMLHttpRequest.prototype.open);
Also I want to know if calling this within
this.readyState === 0
is akin to calling it "when the request first starts"