I've implemented the usual AJAX pool, but when I abort all requests it aborts them at increments of 2 requests, ie. first, third, fifth ... This is basically what I do:
$.ajaxSetup({
beforeSend: function(jqXHR, settings) {
$.xhrPool.push(jqXHR);
},
complete: function(jqXHR, text) {
// Remove a completed request from the array
var index = $.xhrPool.indexOf(jqXHR);
if (index > -1) {
$.xhrPool.splice(index, 1);
}
},
error: function(jqXHR, textStatus, errorThrown) {
// Remove a error request from the array
var index = $.xhrPool.indexOf(jqXHR);
if (index > -1) {
$.xhrPool.splice(index, 1);
}
}
});
function abortAll() {
$.each($.xhrPool, function(key, value) {
value.abort();
});
}
If I do a console.log(value)
inside the $.each
, some of them are undefined. If I do a console.log($.xhrPool)
before the $.each
, they all look ok.
What am I missing?