Jquery Ajax
Jquery Ajax
1 of 17
http://api.jquery.com/jquery.ajax/
Plugins (http://plugins.jquery.com/)
Contribute (http://contribute.jquery.org/)
Support (https://jquery.org/support/)
Events (http://events.jquery.org/)
Ajax (//api.jquery.com
/category/ajax/)
Global Ajax Event
Handlers
(//api.jquery.com
/category
/ajax/globalajax-eventhandlers/)
Helper Functions
(//api.jquery.com
/category
/ajax/helperfunctions/)
Low-Level
Interface
(//api.jquery.com
/category/ajax/lowlevel-interface/)
Shorthand
Methods
(//api.jquery.com
/category
/ajax/shorthandmethods/)
Attributes
(//api.jquery.com
url
Type: String (http://api.jquery.com/Types/#String)
A string containing the URL to which the request is sent.
settings
Type: PlainObject (http://api.jquery.com/Types/#PlainObject)
A set of key/value pairs that configure the Ajax request. All settings
are optional. A default can be set for any option with $.ajaxSetup()
(/jQuery.ajaxSetup/). See jQuery.ajax( settings ) below for a
complete list of all settings.
settings
Type: PlainObject (http://api.jquery.com/Types/#PlainObject)
A set of key/value pairs that configure the Ajax request. All settings
are optional. A default can be set for any option with $.ajaxSetup()
(/jQuery.ajaxSetup/).
9/11/2014 9:13 PM
2 of 17
/category/attributes/)
Callbacks Object
(//api.jquery.com
/category/callbacksobject/)
Core (//api.jquery.com
/category/core/)
CSS (//api.jquery.com
/category/css/)
Data (//api.jquery.com
/category/data/)
Deferred Object
(//api.jquery.com
/category/deferredobject/)
Deprecated
(//api.jquery.com
/category
/deprecated/)
Deprecated 1.3
(//api.jquery.com
/category
/deprecated
/deprecated-1.3/)
Deprecated 1.7
(//api.jquery.com
/category
/deprecated
/deprecated-1.7/)
Deprecated 1.8
(//api.jquery.com
/category
/deprecated
/deprecated-1.8/)
Deprecated 1.10
(//api.jquery.com
/category
/deprecated
/deprecated-1.10/)
Dimensions
(//api.jquery.com
/category
/dimensions/)
http://api.jquery.com/jquery.ajax/
accepts (default:
)
Type: PlainObject (http://api.jquery.com/Types/#PlainObject)
The content type sent in the request header that tells the
server what kind of response it will accept in return.
async (default:
)
Type: Boolean (http://api.jquery.com/Types/#Boolean)
By default, all requests are sent asynchronously (i.e. this is
set to
by default). If you need synchronous requests,
set this option to
. Cross-domain requests and
requests do not support synchronous
operation. Note that synchronous requests may temporarily
lock the browser, disabling any actions while the request is
active. As of jQuery 1.8, the use of
with
jqXHR (
) is deprecated; you must use the
success/error/complete callback options instead of the
corresponding methods of the jqXHR object such as
or the deprecated
.
beforeSend
Type: Function (http://api.jquery.com/Types/#Function)(
jqXHR (http://api.jquery.com/Types/#jqXHR) jqXHR,
PlainObject (http://api.jquery.com/Types/#PlainObject)
settings )
A pre-request callback function that can be used to modify
the jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object before
it is sent. Use this to set custom headers, etc. The jqXHR
and settings objects are passed as arguments. This is an
Ajax Event (/Ajax_Events/). Returning
in the
function will cancel the request. As of jQuery
1.5, the
option will be called regardless of the
type of request.
cache (default:
)
Type: Boolean (http://api.jquery.com/Types/#Boolean)
If set to
, it will force requested pages not to be
cached by the browser. Note: Setting
to false will only
work correctly with HEAD and GET requests. It works by
appending "_={timestamp}" to the GET parameters. The
parameter is not needed for other types of requests, except
in IE8 when a POST is made to a URL that has already been
requested by a GET.
complete
Type: Function (http://api.jquery.com/Types/#Function)(
jqXHR (http://api.jquery.com/Types/#jqXHR) jqXHR, String
(http://api.jquery.com/Types/#String) textStatus )
A function to be called when the request finishes (after
and
callbacks are executed). The function
gets passed two arguments: The jqXHR (in jQuery 1.4.x,
XMLHTTPRequest) object and a string categorizing the
status of the request (
,
,
,
,
, or
). As of
jQuery 1.5, the
setting can accept an array of
9/11/2014 9:13 PM
3 of 17
Effects
(//api.jquery.com
/category/effects/)
Basics
(//api.jquery.com
/category/effects
/basics/)
Custom
(//api.jquery.com
/category/effects
/custom-effects/)
Fading
(//api.jquery.com
/category/effects
/fading/)
Sliding
(//api.jquery.com
/category/effects
/sliding/)
Events
(//api.jquery.com
/category/events/)
Browser Events
(//api.jquery.com
/category/events
/browser-events/)
http://api.jquery.com/jquery.ajax/
Document Loading
(//api.jquery.com
/category/events
/documentloading/)
Event Handler
Attachment
(//api.jquery.com
/category/events
/event-handlerattachment/)
Event Object
(//api.jquery.com
/category/events
/event-object/)
converters (default:
)
Type: PlainObject (http://api.jquery.com/Types/#PlainObject)
An object containing dataType-to-dataType converters. Each
converter's value is a function that returns the transformed
value of the response. (version added: 1.5 (/category
/version/1.5/))
crossDomain (default:
Form Events
(//api.jquery.com
/category/events
)
Type: Boolean (http://api.jquery.com/Types/#Boolean)
If you wish to force a crossDomain request (such as JSONP)
9/11/2014 9:13 PM
4 of 17
/form-events/)
Keyboard Events
(//api.jquery.com
/category/events
/keyboard-events/)
Mouse Events
(//api.jquery.com
/category/events
/mouse-events/)
Forms
(//api.jquery.com
http://api.jquery.com/jquery.ajax/
/category/forms/)
Internals
(//api.jquery.com
/category/internals/)
Manipulation
(//api.jquery.com
/category
/manipulation/)
Class Attribute
(//api.jquery.com
/category
/manipulation
/class-attribute/)
Copying
(//api.jquery.com
/category
/manipulation
/copying/)
dataFilter
Type: Function (http://api.jquery.com/Types/#Function)(
String (http://api.jquery.com/Types/#String) data, String
(http://api.jquery.com/Types/#String) type ) => Object
(http://api.jquery.com/Types/#Object)
A function to be used to handle the raw response data of
XMLHttpRequest.This is a pre-filtering function to sanitize the
response. You should return the sanitized data. The function
accepts two arguments: The raw data returned from the
server and the 'dataType' parameter.
dataType (default:
)
Type: String (http://api.jquery.com/Types/#String)
The type of data that you're expecting back from the server.
If none is specified, jQuery will try to infer it based on the
MIME type of the response (an XML MIME type will yield
XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script
will execute the script, and anything else will be returned as a
string). The available types (and the result passed as the first
argument to your success callback) are:
DOM Insertion,
Around
(//api.jquery.com
/category
/manipulation
/dom-insertionaround/)
DOM Insertion,
Inside
(//api.jquery.com
/category
/manipulation
/dom-insertioninside/)
DOM Insertion,
9/11/2014 9:13 PM
5 of 17
Outside
(//api.jquery.com
/category
/manipulation
/dom-insertionoutside/)
DOM Removal
(//api.jquery.com
/category
/manipulation
/dom-removal/)
DOM
Replacement
(//api.jquery.com
/category
/manipulation
/dom-replacement/)
General Attributes
(//api.jquery.com
/category
/manipulation
/generalattributes/)
Style Properties
(//api.jquery.com
/category
/manipulation
/style-properties/)
Miscellaneous
(//api.jquery.com
/category
/miscellaneous/)
Collection
Manipulation
(//api.jquery.com
/category
/miscellaneous
/collectionmanipulation/)
Data Storage
(//api.jquery.com
/category
/miscellaneous
/data-storage/)
DOM Element
http://api.jquery.com/jquery.ajax/
9/11/2014 9:13 PM
6 of 17
Methods
(//api.jquery.com
/category
/miscellaneous
/dom-elementmethods/)
Setup Methods
(//api.jquery.com
/category
/miscellaneous
/setup-methods/)
Offset
(//api.jquery.com
/category/offset/)
Properties
(//api.jquery.com
/category/properties/)
Properties of
jQuery Object
Instances
(//api.jquery.com
/category
/properties/jqueryobject-instanceproperties/)
Properties of the
Global jQuery
Object
(//api.jquery.com
/category
/properties/globaljquery-objectproperties/)
Removed
(//api.jquery.com
/category/removed/)
Selectors
(//api.jquery.com
/category/selectors/)
Attribute
(//api.jquery.com
/category/selectors
/attributeselectors/)
http://api.jquery.com/jquery.ajax/
jsonpCallback
Type: String (http://api.jquery.com/Types/#String) or Function
(http://api.jquery.com/Types/#Function)()
Specify the callback function name for a JSONP request.
This value will be used instead of the random name
automatically generated by jQuery. It is preferable to let
jQuery generate a unique name as it'll make it easier to
manage the requests and provide callbacks and error
handling. You may want to specify the callback when you
want to enable better browser caching of GET requests. As
of jQuery 1.5, you can also use a function for this setting, in
which case the value of
is set to the return
value of that function.
mimeType
Type: String (http://api.jquery.com/Types/#String)
9/11/2014 9:13 PM
7 of 17
Basic
(//api.jquery.com
/category/selectors
/basiccss-selectors/)
Basic Filter
(//api.jquery.com
/category/selectors
/basic-filterselectors/)
Child Filter
(//api.jquery.com
/category/selectors
/child-filterselectors/)
Content Filter
(//api.jquery.com
/category/selectors
/content-filterselector/)
Form
(//api.jquery.com
/category/selectors
/form-selectors/)
Hierarchy
(//api.jquery.com
/category/selectors
/hierarchyselectors/)
jQuery Extensions
(//api.jquery.com
/category/selectors
/jquery-selectorextensions/)
Visibility Filter
(//api.jquery.com
/category/selectors
/visibility-filterselectors/)
Traversing
(//api.jquery.com
/category/traversing/)
Filtering
(//api.jquery.com
http://api.jquery.com/jquery.ajax/
9/11/2014 9:13 PM
8 of 17
http://api.jquery.com/jquery.ajax/
/category
/traversing
/filtering/)
Miscellaneous
Traversing
(//api.jquery.com
/category
/traversing
/miscellaneoustraversal/)
timeout
Type: Number (http://api.jquery.com/Types/#Number)
Set a timeout (in milliseconds) for the request. This will
override any global timeout set with $.ajaxSetup()
(/jQuery.ajaxSetup/). The timeout period starts at the point
the
call is made; if several other requests are in
progress and the browser has no connections available, it is
possible for a request to time out before it can be sent. In
jQuery 1.4.x and below, the XMLHttpRequest object will be
in an invalid state if the request times out; accessing any
object members may throw an exception. In Firefox 3.0+
only, script and JSONP requests cannot be cancelled by a
timeout; the script will run even if it arrives after the timeout
period.
Tree Traversal
(//api.jquery.com
/category
/traversing/treetraversal/)
Utilities
(//api.jquery.com
/category/utilities/)
Version
(//api.jquery.com
/category/version/)
Version 1.0
(//api.jquery.com
/category/version
/1.0/)
Version 1.0.4
(//api.jquery.com
/category/version
/1.0.4/)
Version 1.1
(//api.jquery.com
/category/version
/1.1/)
Version 1.1.2
(//api.jquery.com
/category/version
/1.1.2/)
Version 1.1.3
(//api.jquery.com
/category/version
/1.1.3/)
Version 1.1.4
(//api.jquery.com
/category/version
traditional
Type: Boolean (http://api.jquery.com/Types/#Boolean)
Set this to
if you wish to use the traditional style of
param serialization (/jQuery.param/).
type (default:
)
Type: String (http://api.jquery.com/Types/#String)
The type of request to make ("POST" or "GET"), default is
"GET". Note: Other HTTP request methods, such as PUT
and DELETE, can also be used here, but they are not
supported by all browsers.
url (default:
)
Type: String (http://api.jquery.com/Types/#String)
A string containing the URL to which the request is sent.
username
Type: String (http://api.jquery.com/Types/#String)
A username to be used with XMLHttpRequest in response to
an HTTP access authentication request.
xhr (default:
)
Type: Function (http://api.jquery.com/Types/#Function)()
Callback for creating the XMLHttpRequest object. Defaults to
the ActiveXObject when available (IE), the XMLHttpRequest
otherwise. Override to provide your own implementation for
XMLHttpRequest or enhancements to the factory.
xhrFields
Type: PlainObject (http://api.jquery.com/Types/#PlainObject)
An object of fieldName-fieldValue pairs to set on the native
object. For example, you can use it
to set
to
for cross-domain requests
if needed.
9/11/2014 9:13 PM
9 of 17
http://api.jquery.com/jquery.ajax/
/1.1.4/)
Version 1.2
(//api.jquery.com
/category/version
/1.2/)
Version 1.2.3
(//api.jquery.com
/category/version
/1.2.3/)
Version 1.2.6
(//api.jquery.com
/category/version
/1.2.6/)
Version 1.3
(//api.jquery.com
/category/version
/1.3/)
Version 1.4
(//api.jquery.com
/category/version
/1.4/)
Version 1.4.1
(//api.jquery.com
/category/version
/1.4.1/)
Version 1.4.2
(//api.jquery.com
/category/version
/1.4.2/)
Version 1.4.3
(//api.jquery.com
/category/version
/1.4.3/)
Version 1.4.4
(//api.jquery.com
/category/version
/1.4.4/)
Version 1.5
(//api.jquery.com
/category/version
/1.5/)
The
function underlies all Ajax requests sent by jQuery. It is
often unnecessary to directly call this function, as several higher-level
alternatives like
and
are
available and are easier to use. If less common options are required,
though,
can be used more flexibly.
At its simplest, the
Version 1.5.1
(//api.jquery.com
/category/version
9/11/2014 9:13 PM
10 of 17
http://api.jquery.com/jquery.ajax/
/1.5.1/)
Version 1.6
(//api.jquery.com
/category/version
/1.6/)
Version 1.7
(//api.jquery.com
/category/version
/1.7/)
Version 1.8
(//api.jquery.com
/category/version
/1.8/)
Version 1.9
(//api.jquery.com
/category/version
/1.9/)
9/11/2014 9:13 PM
11 of 17
http://api.jquery.com/jquery.ajax/
The
reference within all callbacks is the object in the
option passed to
in the settings; if
is not specified,
is a reference to the Ajax settings themselves.
For backward compatibility with
expose the following properties and methods:
,a
object will
and/or
when the underlying request
responded with xml and/or text, respectively
which departs from the
standard by replacing the old value with the new one rather than
concatenating the new value to the old one
No
The
, and
and
options
9/11/2014 9:13 PM
12 of 17
http://api.jquery.com/jquery.ajax/
all accept callback functions that are invoked at the appropriate times.
As of jQuery 1.5, the
and
, and, as of jQuery 1.6,
callback hooks are first-in, first-out managed queues, allowing for more
than one callback for each hook. See Deferred object methods (/category
/deferred-object/), which are implemented internally for these
callback hooks.
The callback hooks provided by
are as follows:
, and
If
or
is specified, no pre-processing occurs. The data is
simply passed on to the success handler, and made available through the
property of the
object.
If
is specified, the response is parsed using
(/jQuery.parseXML/) before being passed, as an
(http://api.jquery.com/Types/#XMLDocument), to the success handler.
The XML document is made available through the
property
of the
object.
9/11/2014 9:13 PM
13 of 17
http://api.jquery.com/jquery.ajax/
If
is specified, the response is parsed using
(/jQuery.parseJSON/) before being passed, as an object, to the success
handler. The parsed JSON object is made available through the
property of the
object.
If
is specified,
will execute the JavaScript that is
received from the server before passing it on to the success handler as a
string.
If
is specified,
will automatically append a query string
parameter of (by default)
to the URL. The
and
properties of the settings passed to
can be
used to specify, respectively, the name of the query string parameter and
the name of the JSONP callback function. The server should return valid
JavaScript that passes the JSON response into the callback function.
will execute the returned JavaScript, calling the JSONP
callback function, before passing the JSON object contained in the
response to the
success handler.
For more information on JSONP, see the original post detailing its use
(http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/).
By default, Ajax requests are sent using the GET HTTP method. If the
POST method is required, the method can be specified by setting a value
for the
option. This option affects how the contents of the
option are sent to the server. POST data will always be transmitted to the
server using UTF-8 charset, per the W3C XMLHTTPRequest standard.
The
to a
The
9/11/2014 9:13 PM
14 of 17
http://api.jquery.com/jquery.ajax/
9/11/2014 9:13 PM
15 of 17
http://api.jquery.com/jquery.ajax/
to
and then
9/11/2014 9:13 PM
16 of 17
http://api.jquery.com/jquery.ajax/
9/11/2014 9:13 PM
http://api.jquery.com/jquery.ajax/
Learning jQuery
Fourth Edition
jQuery in Action
jQuery Succinctly
Cody Lindley
(http://www.syncfusion.com
Jonathan Chaffer
/resources
(http://www.manning.com
(http://www.packtpub.com
/techportal/ebooks
/derosa?a_aid=141d9491&
/learning-jquery/jquery?utm_medium=BizDeva_bid=bdd5b7ad)
with-simplejQuery.org0513)
javascripttechniques-fourthedition/book)
Karl Swedberg and
17 of 17
API (http://api.jquery.com/)
IRC (http://irc.jquery.org/)
GitHub (https://github.com/jquery)
9/11/2014 9:13 PM