I found the following in jsfiddle . It is basically the same as above, except that it will delete every request after its completion. The above solutions just add to the array. So over time, this can become huge if you make a lot of ajax calls. You call $.xhrPool.abortAll(); when you want to cancel all outstanding requests.
// $.xhrPool and $.ajaxSetup are the solution $.xhrPool = []; $.xhrPool.abortAll = function() { $(this).each(function(idx, jqXHR) { jqXHR.abort(); }); $.xhrPool = []; }; $.ajaxSetup({ beforeSend: function(jqXHR) { $.xhrPool.push(jqXHR); }, complete: function(jqXHR) { var index = $.xhrPool.indexOf(jqXHR); if (index > -1) { $.xhrPool.splice(index, 1); } } });
Chuck schneider
source share