Is there any easy way to abandon all outstanding jQuery AJAX requests? My application is capable of pulling off a lot of simultaneous requests, so race becomes problematic. I've put in hackish solutions (namely, putting in a flag that is checked upon request completion), but it would be much nicer to get a global stop all outstanding requests function.
Assign every ajax request as an element of an array:
var requests = [];
requests.push($.ajax({
type: 'POST',
url: '...',
success: successfunc
});
);
And to kill:
$.each(requests, function(i, v) {
v.abort();
});
as the others have said, use the .abort() method. However, this ONLY works on calls within the same domain. once you enter into cross-site calls (with jsonp), then the .abort() method is delegated to null, so wont actually fire/work.
worth noting as this caused me endless debugging time many a small moon ago :)
jim
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With