Skip to content

Instantly share code, notes, and snippets.

@mscharl
Last active December 10, 2015 00:38
Show Gist options
  • Save mscharl/4352571 to your computer and use it in GitHub Desktop.
Save mscharl/4352571 to your computer and use it in GitHub Desktop.
Stoping all ajax request
$.xhrPool = [];
$.xhrPool.abortAll = function() {
$(this).each(function(idx, jqXHR) {
jqXHR.abort();
});
$.xhrPool.length = 0
};
$.ajaxSetup({
beforeSend: function(jqXHR) {
$.xhrPool.push(jqXHR);
},
complete: function(jqXHR) {
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