02.06.2013 Views

DOM Traversal Methods

DOM Traversal Methods

DOM Traversal Methods

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[ 163 ]<br />

Chapter 7<br />

All ajaxError handlers are invoked, regardless of what AJAX request was<br />

completed. If we must differentiate between the requests, we can use the parameters<br />

passed to the handler. Each time an ajaxError handler is executed, it is passed the<br />

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

creation of the request. If the request failed because JavaScript raised an exception,<br />

the exception object is passed to the handler as a fourth parameter. For example, we<br />

can restrict our callback to only handling events dealing with a particular URL:<br />

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

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

$(this).log('Triggered ajaxError handler for<br />

“ajax/missing.html".');<br />

}<br />

});<br />

.ajaxSend()<br />

Registers a handler to be called when AJAX requests begins.<br />

.ajaxSend(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 triggers the ajaxSend event.<br />

All the handlers that have been registered with the .ajaxSend() method are<br />

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

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

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

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

});

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

Saved successfully!

Ooh no, something went wrong!