Skip to content

Instantly share code, notes, and snippets.

@lohic
Last active August 29, 2015 14:02
Show Gist options
  • Save lohic/de48dfcf9acc8f112fa5 to your computer and use it in GitHub Desktop.
Save lohic/de48dfcf9acc8f112fa5 to your computer and use it in GitHub Desktop.
ajax abort
$.xhrPool = [];
$.xhrPool.abortAll = function() {
$(this).each(function(idx, jqXHR) {
jqXHR.abort();
});
$(this).each(function(idx, jqXHR) {
var index = $.inArray(jqXHR, $.xhrPool);
if (index > -1) {
$.xhrPool.splice(index, 1);
}
});
};
$.ajaxSetup({
beforeSend: function(jqXHR) {
$.xhrPool.push(jqXHR);
},
complete: function(jqXHR) {
var index = $.inArray(jqXHR, $.xhrPool);
if (index > -1) {
$.xhrPool.splice(index, 1);
}
}
});
// cf http://stackoverflow.com/questions/1802936/stop-all-active-ajax-requests-in-jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment