ASP. NET + jquery. Ajax details 8-core $. Ajax

Source: Internet
Author: User

Directory (updated articles will be connected, and an article will be updated every two to three days starting from March 13, July 25 ):

ASP. NET + jquery. Ajax details 1-opening section (published on February 25)

ASP. NET + jquery. Ajax details 2-$. Load (published on 2012.07.26)

ASP. NET + jquery. Ajax details 3-$. Get and $. Post (published on February 30)

ASP. NET + jquery. Ajax details 4-$. getjson (published on February 31)

ASP. NET + jquery. Ajax details 5-$. getscript (2012.08.04)

ASP. NET + jquery. Ajax details 6-$. ajaxsetup (2012.08.06)

ASP. NET + jquery. Ajax details 7-Global Ajax events (published on 2012.08.09)

ASP. NET + jquery. Ajax details 8-core $. Ajax (published on February 12)

ASP. NET + jquery. Ajax details 9-serialize and serializearray (February 15)

ASP. NET + jquery. Ajax detailed description: 10-json and XML + are written at the end of the article (published on February 20 !)

 

This is the most important

$. Ajax (options): loads remote data through HTTP requests

 

In a series of previous articles, we have introduced jquery Ajax's easy-to-use high-level implementation. In fact, they are implemented through $. Ajax at the underlying layer. There are two examples at the end of this article:

 

$. Ajax is the core function of Ajax in jquery,
The options parameter supports many parameters, which can be used to completely control Ajax requests. the this object in the Ajax callback function is also an options object. for better flexibility, you can use this core function. The most commonly used get and post functions are simplified, because they can meet the vast majority of requirements and are simple and convenient.

 

$. Ajax () returns the created XMLHTTPRequest object. In most cases, you do not need to directly operate on this object, but in special cases it can be used to manually terminate the request. $. Ajax () has only one parameter: The parameter key/value object, which contains information about various configurations and callback functions.

 

For detailed Parameter options, see. (Because it is rarely used at ordinary times, we recommend that you check the usefulness of these parameters when using them, so you do not have to memorize them .)

 

Parameter Name

Type

Description

URL

String

(Default: Current page address) the address of the request sent.

Type

String

(Default: "Get") Request Method ("Post" or "get"). The default value is "get ". Note: Other HTTP request methods, such as put and delete, can also be used, but are only supported by some browsers.

Timeout

Number

Set the request timeout (in milliseconds ). This setting overwrites the global setting.

Async

Boolean

(Default: True) by default, all requests are asynchronous requests. To send a synchronization request, set this option to false. Note: The synchronous request locks the browser. Other operations can be performed only after the request is completed.

Beforesend

Function

Before sending a request, you can modify the function of the XMLHTTPRequest object, for example, adding a custom HTTP header. The XMLHTTPRequest object is a unique parameter.

Function (XMLHttpRequest ){

This; // The options for this Ajax request
}

Cache

Boolean

(Default: True) New jquery 1.2 function. setting this parameter to false will not load request information from the browser cache.

Complete

Function

Callback Function after the request is complete (called when the request is successful or fails ). Parameter: XMLHTTPRequest object, success information string.

Function (XMLHttpRequest, textstatus ){

This; // The options for this Ajax request
}

Contenttype

String

(Default: "application/X-WWW-form-urlencoded") Content Encoding type when sending information to the server. The default value is applicable to most applications.

Data

Object,

String

The data sent to the server. Will be automatically converted to the request string format. The GET request will be appended to the URL. View the description of the processdata option to disable automatic conversion. It must be in key/value format. If it is an array, jquery automatically corresponds to the same name for different values. For example, {FOO: ["bar1", "bar2"]} is converted to '& Foo = bar1 & Foo = bar2 '.

Datatype

String

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. Available values:

"XML": returns an XML document, which can be processed by jquery.

"Html": returns plain text HTML information, including script elements.

"Script": returns plain text JavaScript code. Results are not automatically cached.

"JSON": Return JSON data.

"Jsonp": jsonp format. When calling a function in the form of jsonp, as shown in
"Myurl? Callback =? "Will jquery be replaced automatically? For the correct function name to execute the callback function.

Error

Function

(Default: automatically determines (XML or HTML) This method is called when a request fails. This method has three parameters: XMLHTTPRequest object, error message, and (possibly) captured error object.

Function (XMLHttpRequest, textstatus, errorthrown ){

// Generally, textstatus and errorthown have only one value.
This; // The options for this Ajax request
}

Global

Boolean

(Default: True) Whether to trigger a global Ajax event. Setting false does not trigger global Ajax events, such as ajaxstart or ajaxstop. Can be used to control different Ajax events

Ifmodified

Boolean

(Default: false) obtain new data only when the server data changes. Use the last-modified header information of the HTTP packet to determine.

Processdata

Boolean

(Default: True) by default, data sent is converted to an object (technically not a string) with the default content type "application/X-WWW-form-urlencoded ". If you want to send the DOM tree information or other information that does not want to be converted, set it to false.

Success

Function

Callback Function after successful request. This method has two parameters: the server returns data and returns the status.

Function (data, textstatus ){

// Data cocould be xmldoc, jsonobj, HTML, text, Etc...
This; // The options for this Ajax request
}

Information from: http://www.w3school.com.cn/jquery/ajax_ajax.asp

Http://www.cnblogs.com/yeer/archive/2009/07/23/1529460.html

There are several Ajax event parameters: beforesend, success, complete, and error. We can define these events to process every Ajax request well.

 

Note:

Because the underlying implementation of all Ajax functions of jquery is jquery. Ajax,

 

$. Get is equivalent:

$. Ajax ({

URL: URL,

Data: data,

Success: success,

Datatype: datatype

});

 

$. Getjson is equivalent:

$. Ajax ({

URL: URL,

Data: data,

Success: callback,

Datatype: JSON

});

 

You can directly change it based on the previous example. I will not go into details here.

 

 

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.