Ajax Methods

The methods listed in the following table are common jQuery Ajax methods that require much less code than standard Ajax.

HTML Example

We will use the following HTML for the examples listed below.

load() Method

The load() method loads data from the server and places the returned HTML into the matched element. This is one of the most common methods used. The load() method also allows you to retrieve a portion of the content from the target URL. For example, when this statement, $(’#result’).load(‘ajax/test.html #container’); is executed, it retrieves the content of ajax/test.html, but then jQuery parses the returned document to find the element with an ID of container. This element, with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded.

Syntax

get() Method

The get() method is used to perform an AJAX HTTP GET request.

Syntax

getScript() Method

The getScript() method is used to get and execute a JavaScript using an AJAX HTTP GET request.

Syntax

post() Method

The post() method is used to perform an AJAX HTTP POST request.

Syntax