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.

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

Shorthand <strong>Methods</strong><br />

These methods perform the more common types of AJAX requests in less code.<br />

$.get()<br />

Loads data from the server using a GET HTTP request.<br />

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

Parameters<br />

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

•<br />

•<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 XMLHttpRequest object that was created.<br />

Description<br />

This is a shorthand AJAX function, which is equivalent to:<br />

$.ajax({<br />

url: url,<br />

data: data,<br />

success: success<br />

});<br />

The callback is passed the returned data, which will be an XML root element or a text<br />

string depending on the MIME type of the response.<br />

Most implementations will specify a success handler:<br />

$.get('ajax/test.html', function(data) {<br />

$('.result').html(data);<br />

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

});<br />

This example fetches the requested HTML snippet and inserts it on the page.<br />

[ 154 ]

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

Saved successfully!

Ooh no, something went wrong!