.ajaxStop( handler() ) Returns: jQuery
Description: Register a handler to be called when all Ajax requests have completed. This is an Ajax Event.
Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop
event. Any and all handlers that have been registered with the .ajaxStop()
method are executed at this time. The ajaxStop
event is also triggered if the last outstanding Ajax request is cancelled by returning false within the beforeSend
callback function.
To observe this method in action, set up a basic Ajax load request:
1
2
3
|
|
Attach the event handler to the document:
1
2
3
|
|
Now, make an Ajax request using any jQuery method:
1
2
3
|
|
When the user clicks the element with class trigger
and the Ajax request completes, the log message is displayed.
Because .ajaxStop()
is implemented as a method of jQuery object instances, you can use the this
keyword to refer to the selected elements within the callback function. As of jQuery 1.8, however, the .ajaxStop()
method should only be attached to document
.
Additional Notes:
- If
$.ajax()
or$.ajaxSetup()
is called with theglobal
option set tofalse
, the.ajaxStop()
method will not fire.
Example:
Hide a loading message after all the Ajax requests have stopped.
1
2
3
|
|