async
: By default, all requests are sent asynchronously, defined with true
. If you need synchronous requests, set this option to false . Cross-Omain requests and dataType: "jsonp"
do not support synchronous operation. Note that synchronous requests can temporarily block the browser, disabling any actions while the request is active.
beforeSend
: To change the request header or perform operations before sending the request, use this function.
cache
: If defined as false
, it will force pages not to be cached by the requested browser.
complete
: The function to be called when the request finishes (after success
and error
call returns are executed).
contents
: A string/regular expression object that determines how jQuery will parse the answer, given its content type.
contentType
: When sending data to the server, use this type of content. The default is "application/x-www-form-urlencoded; charset=UTF-8
", which is good for most cases. If you explicitly pass on a type of content to $.ajax()
, then it is always sent to the server (even if no data is sent).
context
: This object will be the context of all call returns related to Ajax. By default, the context is an object that represents the Ajax settings used in the call ($.ajaxSettings
merged with the definitions passed to $.ajax
).
converters
: An object containing the converters dataType-to-dataType
. The value of each converter is a function that returns the transformed value of the response.
crossDomain
: If you want to force a request crossdomain
(as JSONP) in the same domain, set the value of crossdomain
to true
. This allows, for example, redirecting the server to another domain.
data
: Data to be sent to the server. The format should be variable/value and if you do not leave in this format the function will format automatically.
dataFilter
: A function to be used to manipulate raw response data from XMLHttpRequest
. This is a pre-filtering function to sanitize the answer. You must return the sanitized data. The function takes two arguments: Raw data returned from the server and the parameter dataType
.
dataType
: You define the type of data to be returned by the request. Possible values are: xml, html, json, jsonp, script and text. Configuring this option allows an evaluation of the data that is returned. If this option is omitted the function identifies the data type but does not evaluate.
error
: A function to be called if the request fails. The function takes three arguments: The jqXHR object (in jQuery 1.4.x, Xmlhttprequest), a string describing the type of error that occurred and an optional exception object, if it occurred.
global
: Specifies whether the manipulative events defined in .ajaxSend()
and .ajaxError()
will apply to the current request. By default you are set to true
.
headers
: An additional header object to send along with requests using the Xmlhttprequest transport.
ifModified
: Allow the request to succeed only if the response has changed since the last request. This is done by checking the header Last-Modified
. The default value is false
, ignoring the header.
isLocal
: Allows the current environment to be recognized as "local" (for example, the file system), even if jQuery does not recognize it as such by default. The following protocols are currently recognized as local: file
, *-extension
and widget
. If the isLocal
precise definition of modification, it is recommended to do so once in the $.ajaxSetup()
method.
jsonp
: Replaces the function name callback
in a request JSONP
.
jsonpCallback
: Specifies the function name callback
for a request JSONP
. This value will be used instead of the random name generated automatically by jQuery.
method
: The HTTP method to be used for the request (for example, POST
, GET
, PUT
).
mimeType
: A mime type to replace the mime type XHR.
password
: A password to be used with Xmlhttprequest in response to an HTTP access authentication request.
processData
: This variable is configured to process and transform the information passed to the default application/x-www-form-urlencoded
. If for some reason you do not want this formatting, such as sending in xml format to the server, assign false
for this variable.
scriptCharset
: Applies only when "script" transport is used (for example, requests between domains with data type jsonp
or script
and kind GET
). Defines the charset
attribute in the script tag used in the request. Used when the character set on the local page is not the same as in the remote script.
statusCode
: A code object and HTTP numeric functions to be called when the response has the corresponding code.
success
: If the request is successfully completed, this function is executed, which receives the data received from the server.
timeout
: If you want to limit the time for executing the request, set a value in milliseconds. Not returning success within set time, an error message, configured by you in the function error
, will be shown.
traditional
: Set this option to true
if you want to use the traditional style of parameter serialization.
type
: The method used for the request. Accepts GET
or POST
. The standard is GET
.
url
: Address on the server that will receive the request.
username
: A user name to be used with XMLHttpRequest
in response to an HTTP access authentication request.
xhr
: Callback
to create the object XMLHttpRequest
.
xhrFields
: An object of pairs fieldName-fieldValue
to set about the native XHR object.
There is difference in using type: "post" or type: "POST"?
Not.
Why date is used: JSON.stringify?
It depends on how the server is waiting for the answer of the execution.
For a simple post submission for example, a date is enough:
$("form").serialize()
.
To send a JSON to the server, it uses the JSON.stringify
combined with the contentType: "application/json"
.
The JSON.stringify
serves to transform an object with guys
primitive in a string to be sent in string-like in a
universal JSON format.
The
async
determines asynchrony of the methodajax
for the rest of the code, not for callbacksuccess
. Thesuccess
only occurs when the request is successful, i.e., when whatever you are requesting is available, theasync
determines whether the remnant of its logic awaits (or not) this success. See this discussion– Caio Felipe Pereira