jackocnr
jackocnr

Reputation: 17416

Abort jQuery ajax request without calling error function

In my app, if a user visits a page that triggers an ajax request to load the data, then they quickly navigate to another page, I no longer care about that request, but if I abort it, it triggers the error function, which displays an error alert.

I know you can check inside the error function if it was caused by an "abort", but I would rather not have to do this for every single request. Ideally this would be something you could configure with $.ajaxSetup(), or even an argument you could pass to the abort() function to say this is not an error, this request is just no longer relevant and it doesn't make sense to run my success, error or complete functions.

Upvotes: 0

Views: 1799

Answers (1)

Paulo Lima
Paulo Lima

Reputation: 1238

According to all documentation, the abort call will go through the fault function and can be treated only by verification status:

https://api.jquery.com/jQuery.ajax/

Upvotes: 1

Related Questions