09.02.2015 Views

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

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

A response that the page is not modified is still treated as a success. In this case the<br />

callback will still be executed, but no data will be available. The callback should trap<br />

for this to avoid discarding previously-fetched data.<br />

.load()<br />

Loads data from the server and places the returned HTML into the matched element.<br />

.load(url[, data][, success])<br />

Parameters<br />

• url: A string containing the URL to which the request is sent<br />

• data (optional): A map of data that is sent with the request<br />

• success (optional): A function that is executed if the request succeeds<br />

Return Value<br />

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

Description<br />

This method is the simplest way to fetch data from the server. It is roughly<br />

equivalent to $.get(url, data, success) except that it is a method rather than a<br />

global function and it has an implicit callback function. When a successful response<br />

is detected, .load() sets the HTML contents of the matched element to the returned<br />

data. This means that most uses of the method can be quite simple:<br />

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

The provided callback, if any, is executed after this post-processing has<br />

been performed:<br />

$('.result').load('ajax/test.html', function() {<br />

$(this).log('Load was performed.');<br />

});<br />

The POST method is used if data is provided; otherwise, GET is assumed.<br />

The event handling suite also has a method named .load(). Which one<br />

is fired depends on the set of arguments passed.<br />

[ 156 ]

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

Saved successfully!

Ooh no, something went wrong!