Jqueue uses ajax and jqueueajax

Source: Internet
Author: User

Jqueue uses ajax and jqueueajax

1. get:

$. Ajax ({type: "GET", url: baseUrl + "Showcontent/del_user? Type = 1 & id = "+ id +" & r = "+ Math. random (), async: true, error: function () {alert ("Connection error") ;}, success: function (data) {$ ("# content" ).html (data); // data is the data returned by the background }})

2. post:

$. Ajax ({type: "POST", url: baseUrl + "Showcontent/modify_user? R = "+ Math. random (), async: true, data: $ ('# form_add '). serialize (), // post parameter error: function () {alert ("Connection error") ;}, success: function (data) {$ ("# content" ).html (data); // data is the data returned by the background }})

3. Parameter explanation

(1) type: Request method. The default value is GET. Generally, only "GET" and "POST" are used. Type: string

(2) url: request address; Type: string

(3) async: The default value is true. true: the request is an asynchronous request. false: the request is a synchronous request. (The synchronous request will lock the browser, other user operations can be performed only after the request is completed. Type: bool

(4) timeout: Set the request timeout time (MS); Type: int

(5) cache: The default value is true (when dataType is script, the default value is false). If it is set to false, request information will not be loaded from the browser cache; Type: bool

(6) data: the data sent to the server (for example, a: "a", B: "B" $ ('# formid '). serialize () automatically converts form forms); Type: string

(7) dataType: The expected data type returned by the server. If this parameter is not specified, JQuery will automatically return responseXML or responseText Based on the mime information of the http package and pass it as a callback function parameter .); Type: string

The available types are as follows:

Xml: the XML document is returned and can be processed by JQuery.

Html: returns plain text HTML information. 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 that in the remote request

All post requests are converted to get requests.

Json: Return JSON data.

Jsonp: JSONP format. When a function is called in the form of SONP, such as myurl? Callback = ?, JQuery will automatically Replace the last

"?" For the correct function name to execute the callback function.

Text: returns a plain text string.

(8) beforeSend: before sending a request, you can modify the function of the XMLHttpRequest object, for example, adding a custom HTTP header. In beforeSend, if false is returned, the ajax request can be canceled. The XMLHttpRequest object is a unique parameter.

Function (XMLHttpRequest ){

This; // The options parameter passed when calling this ajax request

}

(9) complete: the callback function called after the request is complete (called when the request is successful or fails ). Parameter: XMLHttpRequest object and a string that describes the successful request type.

Function (XMLHttpRequest, textStatus ){

This; // The options parameter passed when calling this ajax request

}

(10) success: the callback function called after the request is successful. There are two parameters.

1) The data is 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, etc.

This; // The options parameter passed when calling this ajax request

(12) error: the function called when the request fails. This function has three parameters: XMLHttpRequest object, error message, and captured error object (optional ).

Ajax event functions are as follows:

Function (XMLHttpRequest, textStatus, errorThrown ){

// Generally, textStatus and errorThrown only contain one of the information.

This; // The options parameter passed when calling this ajax request

}

(13) contentType: when the message is sent to the server, the content encoding type is "application/x-www-form-urlencoded" by default ". This default value is suitable for most applications. Type: string

(14) dataFilter: A function used to pre-process the original data returned by Ajax.

Provides two parameters: data and type. Data is the original data returned by Ajax, and type is provided when jQuery. ajax is called.

DataType parameter. The value returned by the function will be further processed by jQuery.

Function (data, type ){

// Return the processed data

Return data;

}

(15) global: The default value is true. Indicates whether to trigger a global ajax event. Setting false does not trigger global ajax events. ajaxStart or ajaxStop can be used to control various ajax events. Type: bool

(16) ifModified: The default value is false. Obtain New data only when the server data changes. The server data change judgment is based on the Last-Modified header information. The default value is false, indicating that header information is ignored. Type: bool

(17) jsonp: indicates the name of the callback function in a jsonp request. This value is used to replace "callback =? "Callback" in the URL parameter in this GET or POST request; Type: string

For example: {jsonp: 'onjsonpload'} causes "onJsonPLoad =? "To the server.

(18) username: the user name used to respond to the HTTP access authentication request; Type: string

(19) password: the password used to respond to the HTTP access authentication request; Type: string

(20) processData: The default value is true. By default, the sent data will be converted to an object (technically not a string) in combination with the default content type "application/x-www-form-urlencoded"; Type: bool

If you want to send DOM tree information or other information that does not want to be converted, set it to false.

(21) scriptCharset: only when the ype is "jsonp" or "script" and the type is GET, it is used to forcibly modify the character set (charset ). It is usually used in different local and remote content encoding; Type: string

 

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.