Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: aborting ajax will trigger done or fail?

Tags:

jquery

ajax

I don't understand a thing about $.ajax, .done and .fail

I start my ajax call, assigning this to a variabile.

At next ajax call i test if variable is defined, and then i call abort.

I'm not able to undertsand if .abort() causes execution of .done or not.

If it causes .done, how to check status and detect aborted call ?

From http://api.jquery.com/jQuery.ajax/#jqXHR :

In particular, calling .abort() on the object will halt the request before it completes.

... so I understand that .done will not be fired after a .abort, right ?

like image 607
realtebo Avatar asked Jan 21 '13 09:01

realtebo


People also ask

How do I know if AJAX request is complete?

The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.

How do you abort an AJAX call?

Just use ajax.abort(); } //then you make another ajax request $. ajax( //your code here );

Does AJAX wait for response?

Ajax requests do just that. With this, all codes following this one will execute immediately; you will not have to wait until the function returns. This way, your user would not have to wait for findItem() to return a result. Of course, because you still need an answer, you would have to include a callback.

Which method cancels the current request?

abort() method aborts the request if it has already been sent. When a request is aborted, its readyState is changed to XMLHttpRequest.


1 Answers

The second argument to the fail callback is textStatus, for an aborted request that should be "abort". I wouldn't expect the done callback to be fired.

like image 159
Douglas Avatar answered Oct 01 '22 13:10

Douglas