Appendix G. AJAX Methods

Method

Description

Return Value

AJAX Requests

jQuery.ajax(options)

$.ajax(options)

Allows you to pass an object literal specifying various options in key, value pairs. For the complete list of options, see the "Options" section. This method is used by jQuery's other AJAX methods to make AJAX requests. You should only use this method if you require finer-grained control over an AJAX request than is possible with jQuery's other methods.

XMLHttpRequest

load(url, [data],
[function])

Loads HTML from a remote file and inserts the HTML inside of the selected elements. The data argument (optional) is specified as an object literal, defining the data you want to pass to the server in key, value pairs. The function argument (also optional) is the callback method that will handle the data once it is returned from the server.

jQuery

jQuery.get(url, [data],
[function], [type])

$.get(url, [data],
[function], [type]))

Initiates an HTTP request using the GET method.

XMLHttpRequest

jQuery.getJSON(url,
[data], [function])

$.getJSON(url, [data],
[function])

Initiates an HTTP request using the GET method, in which the response will be JSON-formatted data.

XMLHttpRequest

jQuery.getScript(url,
[function])

$.getScript(url,
[function])

Loads and executes a new JavaScript file via the GET method asynchronously.

XMLHttpRequest

jQuery.post(url, [data],
[function], [type])

$.post(url, [data],
[function], [type])

Initiates an HTTP request using the POST method.

XMLHttpRequest

AJAX Events

ajaxComplete( ...

Get Beginning JavaScript® and CSS Development with jQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.