forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajaxStart.xml
More file actions
34 lines (33 loc) · 1.9 KB
/
ajaxStart.xml
File metadata and controls
34 lines (33 loc) · 1.9 KB
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
<entry type='method' name="ajaxStart" return="jQuery">
<signature>
<added>1.0</added>
<argument name="handler()" type="Function">
<desc>The function to be invoked.</desc>
</argument>
</signature>
<desc>Register a handler to be called when the first Ajax request begins. This is an <a href='http://docs.jquery.com/Ajax_Events'>Ajax Event</a>.</desc>
<longdesc><p>Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the <code>ajaxStart</code> event. Any and all handlers that have been registered with the <code>.ajaxStart()</code> method are executed at this time.</p>
<p>To observe this method in action, we can set up a basic Ajax load request:</p>
<pre><div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div></pre>
<p>We can attach our event handler to any element:</p>
<pre>$('.log').ajaxStart(function() {
$(this).text('Triggered ajaxStart handler.');
});</pre>
<p>Now, we can make an Ajax request using any jQuery method:</p>
<pre>$('.trigger').click(function() {
$('.result').load('ajax/test.html');
});</pre>
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request is sent, the log message is displayed.</p>
<p><strong>Note:</strong> Because <code>.ajaxStart()</code> is implemented as a method of jQuery object instances, we can use the <code>this</code> keyword as we do here to refer to the selected elements within the callback function.</p>
</longdesc>
<example>
<desc>Show a loading message whenever an Ajax request starts (and none is already active).</desc>
<code><![CDATA[$("#loading").ajaxStart(function(){
$(this).show();
});]]></code>
</example>
<category slug="ajax/global-ajax-event-handlers"/>
<category slug="version/1.0"/>
</entry>