forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxStop.xml
45 lines (45 loc) · 2.09 KB
/
ajaxStop.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?xml version="1.0"?>
<entry type="method" name="ajaxStop" return="jQuery">
<title>.ajaxStop()</title>
<desc>Register a handler to be called when all Ajax requests have completed. This is an <a href="/Ajax_Events/">Ajax Event</a>.</desc>
<signature>
<added>1.0</added>
<argument name="handler()" type="Function">
<desc>The function to be invoked.</desc>
</argument>
</signature>
<longdesc>
<p>Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the <code>ajaxStop</code> event. Any and all handlers that have been registered with the <code>.ajaxStop()</code> method are executed at this time. The <code>ajaxStop</code> event is also triggered if the last outstanding Ajax request is cancelled by returning false within the <code>beforeSend</code> callback function. </p>
<p>To observe this method in action, set up a basic Ajax load request:</p>
<pre><code>
<div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>
</code></pre>
<p>Attach the event handler to the document:</p>
<pre><code>
$( document ).ajaxStop(function() {
$( ".log" ).text( "Triggered ajaxStop handler." );
});
</code></pre>
<p>Now, make an Ajax request using any jQuery method:</p>
<pre><code>
$( ".trigger" ).click(function() {
$( ".result" ).load( "ajax/test.html" );
});
</code></pre>
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes, the log message is displayed.</p>
<p><strong>As of jQuery 1.8, the <code>.ajaxStop()</code> method should only be attached to <code>document</code>.</strong></p>
</longdesc>
<note id="ajax-global-false" type="additional" data-title=".ajaxStop()"/>
<example>
<desc>Hide a loading message after all the Ajax requests have stopped.</desc>
<code><![CDATA[
$( document ).ajaxStop(function() {
$( "#loading" ).hide();
});
]]></code>
</example>
<category slug="ajax/global-ajax-event-handlers"/>
<category slug="version/1.0"/>
</entry>