AJAX - The Complete Reference

(avery) #1

224 Part II: Applied Ajax^


Property Description
async A Boolean value indicating if the request is asynchronous or not. true by default.

beforeSend A callback function to invoke before the request is invoked. Often used to per form
tasks such as setting headers that the librar y may not support directly. The only
parameter passed to the set function is the XHR object itself that you can then
per form native methods on like setRequestHeader().
complete A callback function to be called after the response is received and any success
or error callbacks are invoked. The function is passed the XHR object and string
indicating the success or failure of the request.
contentType The encoding type when sending data to the ser ver. The default is application/
x-www-form-urlencoded, as expected.
data The data to be sent to the ser ver. You may pass a string, an object, or an array.
Strings will be assumed to be a quer y string, while objects and arrays will be
serialized into the appropriate name-value pair format. If you pass an object,
note that it is a JSON style format you should specify as a standard JavaScript
object literal like so { name : "Thomas" , author : true}. Also note
that in order to bind a sequence of values with the same name, you should use
an array as the property value like so: { names : ["Thomas", "Sylvia",
"Graham", "Olivia"] }.
dataType A string indicating the expected data type from the ser ver. Allowed values are
xml, html, script, and json. If no value is indicated, the environment will
assume that the Content-Type header on the response correctly indicates the
expected content. As of version 1.1.3.1, errors are not raised upon incorrect data
(determined by raw source inspection).
error A function to be called upon request failure. The function is invoked with the XHR,
an error string, and an exception object if one exists.
global A Boolean flag to indicate if the global handlers ajaxStart() and ajaxStop()
should be ignored or not. By default the value is true indicating those methods be
called, a false value skips them.
ifModified A Boolean value set to false by default that indicates if the request should be
successful only if the content has been modified since the last request.
processData A Boolean flag indicating if you want to process data automatically or not. The
default is true, but if you set it to false you will need to transform data into
whatever format you want to encode and use.
success A callback function to be invoked upon successful response. The function will be
invoked with a single parameter containing the data of the response.
timeout The number of milliseconds to wait before a timeout. This will override any global
timeout for the particular request in question. No timeout is set by default.
type A string indicating the HTTP method to be used. Assumed to be GET by default.
url The string of the URL to make the request to.

TABLE 5-11 Communication Parameters for jQuer y’s $.ajax() Method
Free download pdf