-
-
Save tegomass/5df891403b4a90d4aa036aba93c75916 to your computer and use it in GitHub Desktop.
Cancel all jQuery AJAX requests currently running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xhrQueue = []; | |
$(document).ajaxSend(function(event,jqxhr,settings){ | |
xhrQueue.push(jqxhr); | |
}); | |
$(document).ajaxComplete(function(event,jqxhr,settings){ | |
let i; | |
if((i=$.inArray(jqxhr,xhrQueue)) > -1){ | |
xhrQueue.splice(i,1); | |
} | |
}); | |
function ajaxAbort(){ | |
let i=0; | |
while(xhrQueue.length){ | |
xhrQueue[i++].abort(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment