jquery Ajax methods and the detailed parameters

Source: Internet
Author: User
Tags browser cache

jquery Ajax methods and the detailed parameters

1.$.ajax () has only one parameter: The parameter Key/value object, which contains the configuration and callback function information.

Parameter list:

The data sent to the server.

If the data datatype is a JavaScript object or array, jquery automatically calls the Jquery.param () method before committing to encode the data to be sent as "application/x-www-form-urlencoded" Formatted data (that is, name=value&name1=value1); JavaScript objects must be in key/value format; If an array, JQuery automatically corresponds to the same name for different values. such as {foo:["bar1", "Bar2"]} is converted to ' &foo=bar1&foo=bar2 ';

If the data data type is string, it is directly default to "application/ x-www-form-urlencoded "format encoding complete, no longer converted. The

ProcessData option controls whether conversions are performed. This option defaults to true.

TD valign= "Top" width= "419" >
Name of parameter Type Describe
Url String (Default: Current page address) sends the requested address.
Type String (Default: "Get") The Request method ("POST" or "get"), the default is "get". Note: Other HTTP request methods, such as PUT and DELETE, can also be used, but only some browsers support it.
Timeout Number Sets the request time-out (in milliseconds). This setting overrides the global settings.
Async Boolean (default: TRUE) by default, 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 for the request to complete before it can be executed.
Beforesend Function You can modify the functions of the XMLHttpRequest object before sending the request, such as adding a custom HTTP header. The XMLHttpRequest object is the only parameter.
function (XMLHttpRequest) {
This The options for this AJAX request }
Cache Boolean (default: TRUE) JQuery 1.2 new feature, set to False will not load the request information from the browser cache.
Complete Function The callback function after the request completes (called when the request succeeds or fails). Parameters: XMLHttpRequest Object, Success information string.
function (XMLHttpRequest, textstatus) {
This The options for this AJAX request }
ContentType String

(Default: "application/x-www-form-urlencoded") the content encoding type when sending information to the server. The default values are suitable for most applications. Tells the server to submit the data format from the browser.

For example, if we use the Json2.js method json.stringify (obj) format as a JSON string when we submit the data, then the default commit will report an error. At this point, you need to specify the content format for the submission: "Application/json".

data String
dataType string

Expected data type returned by the server. Set the contents of the "Accept" field in Httpheader, telling the server browser what type of data format to return, and jquery will process the returned data based on that type. If not specified, jquery automatically returns Responsexml or ResponseText based on the HTTP packet MIME information and is passed as a callback function argument, with the available values:

"xml": Returns an XML document that can be processed with jQuery.

HTML: Returns plain text HTML information, including the script element.

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

"JSON": Returns the JSON data. jquery automatically translates the returned string format data into JavaScript objects for easy access using the Obj.property format. If this option is not specified, jquery does not automatically convert even if it returns a JSON-formatted string. The

"JSONP": jsonp  format. When calling functions using  JSONP , such as "myurl?callback=?" JQuery is automatically replaced? is the correct function name to execute the callback function.

Error Function (Default: This method is called when a request for automatic judgment (XML or HTML) fails.) This method has three parameters: the XMLHttpRequest object, the error message, and (possibly) the error object being captured.
function (XMLHttpRequest, textstatus, Errorthrown) {
Normally textstatus and Errorthown have only one of the values this ;//The options for this AJAX request }
Global Boolean (default: TRUE) whether to trigger global AJAX events. Setting to FALSE will not trigger global AJAX events, such as Ajaxstart or Ajaxstop. Can be used to control different AJAX events
Ifmodified Boolean (default: false) to get new data only when the server data changes. Use the HTTP packet last-modified header information to determine.
ProcessData Boolean (default: TRUE) by default, the sent data is converted to an object (technically not a string) to match the default content type "application/x-www-form-urlencoded". Set to False if you want to send DOM tree information or other information that you do not want to convert.
Success Function The callback function after the request succeeds. This method has two parameters: the server returns data, returns the status
function (data, textstatus) {
Data could be xmldoc, jsonobj, HTML, text, etc ... This The options for this AJAX request }

2. Jquery.get(URL, [data], [callback], [type]): Use Get method to make asynchronous request.

Parameters:
URL (String): The URL address of the sending request.
Data (MAP): (optional) to be sent to the server, in the form of Key/value key-value pairs.
Callback (function): (optional) The callback function when loading succeeds (the method is called only if the return state of response is success).
Type (String): (optional) The official description is: Type of data to be sent. The type that should actually be requested for the client (Json,xml, etc.)

3. Jquery.post(URL, [data], [callback], [type]): Use post to make asynchronous requests

Parameters:
URL (String): The URL address of the sending request.
Data (MAP): (optional) to be sent to the server, in the form of Key/value key-value pairs.
Callback (function): (optional) The callback function when loading succeeds (the method is called only if the return state of response is success).
Type (String): (optional) The official description is: Type of data to be sent. The type that should actually be requested for the client (Json,xml, etc.)

jquery Ajax methods and the detailed parameters

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.