Where/how to abort previous server-side HTTP request?
Where/how to abort previous server-side HTTP request?
Where and how can I access any active XHR request so I can abort it?
I have a server-side table. There are various controls on the toolbar that will cause datatables to fire a new HTTP request to the server and I want to ensure that if there is a previous request still in progress that I abort it using jqXHR.abort(). What I can't figure out is where to do this. For example, there is the preXhr.dt event that fires before a new request is made, but can I access any previously active requests in this event handler? For example, if I look at settings.jqXHR when the event fires will it be the previous request or the upcoming new request?
I've looked through all the posts and documentation I could find...
Answers
You could set a global variable on preXhr. Something like
xhrOngoing = true;
Then on xhr you would set
xhrOngoing = false;
Then on preXhr you can abort the next request if xhrOngoing is still true.
https://datatables.net/reference/event/preXhr
https://datatables.net/reference/event/xhr