02.06.2013 Views

DOM Traversal Methods

DOM Traversal Methods

DOM Traversal Methods

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

AJAX <strong>Methods</strong><br />

We can attach our event handler to any element:<br />

$('.log').ajaxStop(function() {<br />

$(this).log('Triggered ajaxStop handler.');<br />

});<br />

Now, we can make an AJAX request using any jQuery method:<br />

$('.trigger').click(function() {<br />

$('.result').load('ajax/test.html');<br />

});<br />

When the user clicks the button and the AJAX request completes, the log message<br />

is displayed.<br />

Because .ajaxStart(), .ajaxStop(), .ajaxSend(),<br />

ajaxError(), and .ajaxComplete() are implemented as a methods<br />

rather than global functions, we can use the keyword this as we do here<br />

to refer to the selected elements within the callback function.<br />

.ajaxSuccess()<br />

Registers a handler to be called when AJAX requests are successfully completed.<br />

.ajaxSuccess(handler)<br />

Parameters<br />

•<br />

handler: The function to be invoked<br />

Return Value<br />

The jQuery object, for chaining purposes.<br />

Description<br />

Whenever an AJAX request is successfully completed, jQuery triggers the<br />

ajaxSuccess event. All the handlers that have been registered with the<br />

.ajaxSuccess() method are executed at this instant of time.<br />

To observe this method in action, we can set up a basic AJAX load request:<br />

Trigger<br />

<br />

<br />

[ 166 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!