Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (36 sloc) 2 KB
<?xml version="1.0"?>
<entry type="method" name="ajaxStart" return="jQuery">
<argument name="handler()" type="Function">
<desc>The function to be invoked.</desc>
<desc><![CDATA[Register a handler to be called when the first Ajax request begins. This is an <a href=''>Ajax Event</a>.]]></desc>
<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><code>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
&lt;div class="result"&gt;&lt;/div&gt;
&lt;div class="log"&gt;&lt;/div&gt;</code></pre>
<p>We can attach our event handler to any element:</p>
<pre><code>$('.log').ajaxStart(function() {
$(this).text('Triggered ajaxStart handler.');
<p>Now, we can make an Ajax request using any jQuery method:</p>
<pre><code>$('.trigger').click(function() {
<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>
<desc>Show a loading message whenever an Ajax request starts (and none is already active).</desc>
<category slug="ajax/global-ajax-event-handlers"/>
<category slug="version/1.0"/>
Jump to Line
Something went wrong with that request. Please try again.