JQuery Ajax $.ajax () method parameters in detail

Source: Internet
Author: User
Tags character set http request json requires script tag browser cache

Original posts: http://blog.sina.com.cn/s/blog_4f925fc30100la36.html

I also take notes:

URL: The requested address is requested for a parameter of type string, (the current page address is assumed to be the default).

Type: A parameter of type string is required, and the request method (post or get) defaults to get. Note Other HTTP request methods, such as put and

Delete can also be used, but only some browsers support it.

Timeout: Requires a parameter of type number to set the request time-out (in milliseconds). This setting overrides the global setting of the $.ajaxsetup () method


Async: Requires a parameter of type Boolean, which is set to True by default and all requests are asynchronous requests.

If you need to send a synchronization request, set this option to false. Note that the sync request will lock the browser, and the user's other actions must wait

The request is complete before it can be executed.

Cache: A parameter that is required to be of type Boolean, which is true by default (False when datatype is a script).

Set to False to not load the request information from the browser cache.

Data: A parameter that is required to be an object or string that is sent to the server. Automatically converts to a string if it is not already a string

Expression The GET request will be appended to the URL. To prevent this automatic conversion, you can view the ProcessData option. The object must be a key/value grid

, for example {foo1: "Bar1", Foo2: "Bar2"} is converted to &FOO1=BAR1&FOO2=BAR2. If it is an array, jquery will automatically be a different

The value corresponds to the same name. For example {foo:["Bar1", "Bar2"]} is converted to &FOO=BAR1&FOO=BAR2.

DataType: A parameter of type string is required and the expected data type is returned by the server. If not specified, jquery is automatically mime based on the HTTP package

The information returns Responsexml or ResponseText, and is passed as a callback function parameter.

The following types are available:

XML: Returns an XML document that can be processed with jquery.

HTML: Returns plain text HTML information, and the included script tag is executed when the DOM is inserted.

Script: Returns plain text JavaScript code. Results are not automatically cached. Unless the cache parameter is set. Note in the remote request

(not under the same domain), all post requests are converted to get requests.

JSON: Returns the JSON data.

JSONP:JSONP format. When a function is called using the Sonp form, for example Myurl?callback=?,jquery will automatically replace the latter

“?” is the correct function name to execute the callback function.

Text: Returns a plain text string.

Beforesend: A function that requires a parameter of type function that can modify a XMLHttpRequest object before sending a request, such as adding a custom

HTTP headers. If you return False in Beforesend, you can cancel this Ajax request. The XMLHttpRequest object is the only parameter


function (XMLHttpRequest) {

This Options parameters passed when calling this Ajax request


Complete: A parameter that is required to be a function type, called when the request is completed (invoked when the request succeeds or fails).

Parameters: The XMLHttpRequest object and a string that describes the successful request type.

function (XMLHttpRequest, textstatus) {

This Options parameters passed when calling this Ajax request


Success: A callback function called after a successful request for a parameter of function type, with two parameters.

(1) The data returned by the server and processed according to the datatype parameter.

(2) A string describing the status.

function (data, textstatus) {

Data may be xmldoc, jsonobj, HTML, text, and so on

This Options parameters passed when calling this Ajax request

Error: A function that requires a parameter of type function, which is called when the request fails. The function has 3 parameters, that is, the XMLHttpRequest object, the wrong

Error message, and optionally, the wrong object to be captured.

The Ajax event functions are as follows:

function (XMLHttpRequest, textstatus, Errorthrown) {

Normally textstatus and Errorthrown only one of them contains information

This Options parameters passed when calling this Ajax request


ContentType: Requires a parameter of type string, when sending information to the server, the content encoding type is default

To "application/x-www-form-urlencoded". This default value is suitable for most applications.

Datafilter: A function that requires the preprocessing of the original data returned by Ajax as a parameter of the function type.

Provides data and type two parameters. Data is the original information returned by Ajax, type is provided when calling Jquery.ajax

The datatype parameter. The value returned by the function will be further processed by jquery.

function (data, type) {

Returns the processed data

return data;


Global: A parameter that is required to be of type Boolean, which is true by default. Indicates whether global AJAX events are triggered. Set to False will not trigger the global

Ajax events, Ajaxstart or ajaxstop, can be used to control various AJAX events.

Ifmodified: A parameter of type Boolean is required, and the default is False. Get new data only when the server data changes.

Server data changes are based on the last-modified header information. The default value is False, which ignores header information.

Jsonp: Requires a String type parameter to override the name of the callback function in a JSONP request.

This value is used instead of the "callback=?" The "callback" part of the URL parameter in the GET or POST request, such as

{jsonp: ' onjsonpload '} will cause the "onjsonpload=?" passed to the server.

Username: A parameter of type string that is required to respond to the user name of the HTTP access authentication request.

Password: A parameter of type string that is required to respond to the password for HTTP access authentication request.

ProcessData: A parameter that is required to be of type Boolean, which is true by default. By default, the sent data is converted to an object (from a technical perspective

Not a string) to match the default content type "application/x-www-form-urlencoded". If you want to send the DOM

Tree information or other information you do not want to convert, set to False.

Scriptcharset: A parameter that is required to be of type string, only if the request is datatype as "JSONP" or "script" and the type is get

is used to force the modification of the character set (CharSet). Typically used when local and remote content encodings are different.

Case code:

$ (function () {

$ (' #send '). Click (function () {

$.ajax ({

Type: "GET",

URL: "Test.json",

Data: {username:$ ("#username"). Val (), content:$ ("#content"). Val ()},

DataType: "JSON",

Success:function (data) {


Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.