I have a problem, when submitting a form all active ajax request fail, and that triggers error event.
How to stop all active ajax requests in jQuery without trigerring error event?
I have a problem, when submitting a form all active ajax request fail, and that triggers error event.
How to stop all active ajax requests in jQuery without trigerring error event?
I found it too easy for multiple requests.
step1: define a variable at top of page:
step2: set beforeSend in all ajax requests:
step3: use it whereever you required:
Every time you create an ajax request you could use a variable to store it:
Then you can abort the request:
You could use an array keeping track of all pending ajax requests and abort them if necessary.
Better to use independent code.....
The following snippet allows you to maintain a list (pool) of request and abort them all if needed. Best to place in the
<HEAD>
of your html, before any other AJAX calls are made.I extended mkmurray and SpYk3HH answer above so that xhrPool.abortAll can abort all pending requests of a given url :
Usage is same except that abortAll can now optionally accept a url as a parameter and will cancel only pending calls to that url
Throwing my hat in. Offers
abort
andremove
methods against thexhrPool
array, and is not prone to issues withajaxSetup
overrides.