forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxStop.xml
52 lines (52 loc) · 2.39 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
46
47
48
49
50
51
52
<?xml version="1.0"?>
<entry type="method" name="on" return="jQuery">
<title>ajaxStop event</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.7</added>
<argument name=""ajaxStop"" type="string">
<desc>The string <code>"ajaxStop"</code>.</desc>
</argument>
<argument name="handler" type="Function">
<desc>The function to be invoked.</desc>
</argument>
</signature>
<longdesc>
<div class="warning">
<p>This page describes the <code>ajaxStop</code> event. For the deprecated <code>.ajaxStop()</code> method, see <a href="/ajaxStop-shorthand/"><code>.ajaxStop()</code></a>.</p>
</div>
<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 registered <code>ajaxStop</code> handlers 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 ).on( "ajaxStop", function() {
$( ".log" ).text( "Triggered ajaxStop handler." );
} );
</code></pre>
<p>Now, make an Ajax request using any jQuery method:</p>
<pre><code>
$( ".trigger" ).on( "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>
</longdesc>
<note id="global-ajax-event" type="additional" data-title="ajaxStop"/>
<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 ).on( "ajaxStop", function() {
$( "#loading" ).hide();
} );
]]></code>
</example>
<category slug="ajax/global-ajax-event-handlers"/>
<category slug="version/1.0"/>
<category slug="version/1.7"/>
</entry>