AJAX requests: is there a way to debounce and cancel pending requests?


#1

I want to know if there is a way using app.request to perform debouncing and avoid
unnecessary requests and a way to cancel old pending requests this is very useful when entering a page that perform on pageInit a app.request Ajax request and I click in the middle of the request back to return previous page…

In my case the Ajax request still running when go back and I will love to debounce to avoid unnecessary requests running…

is there a way to do this using app.request for Ajax requests ?
thanks for the ideas!


#2

App.request returns a plain xhr object. You can save that reference to a global variable, which you set to null when the request finishes normally. Then, in your “back” event, check if there’s a reference to a pending request, and use XMLHttp​Request​.abort() to cancel the request.


#3

I will try that thanks :sunglasses: :+1: