1
我想根據變量立即拒絕所有的AJAX請求。我明白如何掛接XMLHttpRequest,但不知道如何拒絕它。拒絕所有的AJAX請求
(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);
此外,我想知道,如果內 this.readyState === 0
調用這個類似於稱之爲「當請求第一次啓動」
爲什麼downvote ???? –
我對所有請求感興趣 – Tester232323
@ Tester232323:那麼你需要保留你的所有請求在一些數組中,然後你可以調用它們中止......你需要維護一個請求變量 –