-
-
Save DmitriyWebDev/b65bfa10d09230bf6ab5b6cd7cb4400c to your computer and use it in GitHub Desktop.
Stop all ajax request
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
// Stop all ajax request by http://tjrus.com/blog/stop-all-active-ajax-requests | |
$.xhrPool = []; // array of uncompleted requests | |
$.xhrPool.abortAll = function() { // our abort function | |
$(this).each(function(idx, jqXHR) { | |
jqXHR.abort(); | |
}); | |
$.xhrPool.length = 0 | |
}; | |
$.ajaxSetup({ | |
beforeSend: function(jqXHR) { // before jQuery send the request we will push it to our array | |
$.xhrPool.push(jqXHR); | |
}, | |
complete: function(jqXHR) { // when some of the requests completed it will splice from the array | |
var index = $.xhrPool.indexOf(jqXHR); | |
if (index > -1) { | |
$.xhrPool.splice(index, 1); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment