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 />

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 is about to begin, the log<br />

message is displayed.<br />

All ajaxSend handlers are invoked, regardless of what AJAX request is to be sent. If<br />

we must differentiate between the requests, we can use the parameters passed to the<br />

handler. Each time an ajaxSend handler is executed, it is passed the event object, the<br />

XMLHttpRequest object, and the settings object that was used in the creation of the<br />

request. For example, we can restrict our callback to only handling events dealing<br />

with a particular URL:<br />

$('.log').ajaxSend(function(e, xhr, settings) {<br />

if (settings.url == 'ajax/test.html') {<br />

$(this).log('Triggered ajaxSend handler for “ajax/test.html".');<br />

}<br />

});<br />

.ajaxStart()<br />

Registers a handler to be called when the first AJAX request begins.<br />

.ajaxStart(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 about to be sent, jQuery checks whether there are<br />

any other outstanding AJAX requests. If none are in progress, jQuery triggers the<br />

ajaxStart event. All the handlers that have been registered with the .ajaxStart()<br />

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

[ 164 ]

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

Saved successfully!

Ooh no, something went wrong!