Jquery ajax-related methods

Source: Internet
Author: User
Tags getscript

Jquery ajax-related methods

JQuery. get ()
Use an http get request to load data from the server.
JQuery. get (url [, data] [, success (data, textStatus, jqXHR)] [dtaType])
Url: a URL containing the sent request
Key-value pairs after the string sent by data to the server
Success () the callback function when the request is successful
The expected data returned by the dataType from the server.
Usage:
$. Get ("test. cgi", {name: "John", time: "2 "},
Function (data ){
Alert ("Data Loaded:" + data );
});


JQuery. getJSON ()
Use an http get request server to load JSON-encoded data.
JQuery. getJSON (url [, data] [, success (data, textStatus, jqXHR)])
Url: a URL containing the sent request
Key-value pairs after the string sent by data to the server
Success () the callback function when the request is successful


JQuery. getScript ()
Use an http get request to load and execute a JavaScript file from the server.
JQuery. getScript (url [success (script, textStatus, jqXHR)])
Url: a URL containing the sent request
Key-value pairs after the string sent by data to the server
Usage:
$. GetScript ("ajax/test. js", function (data, textStatus, jqxhr ){
Console. log (data); // data returned
Console. log (textStatus); // success
Console. log (jqxhr. status); // 200
Console. log ('Load was saved med .');
});


JQuery. post ([settings])
Use an http post request to load data from the server.
JQuery. post (url [, data] [, success (data, textStatus, jqXHR)] [, dataType])
Url: a URL containing the sent request
Key-value pairs after the string sent by data to the server
Success () the callback function when the request is successful
Usage:
$. Post ("test. php", {name: "John", time: "2 "},
Function (data ){
Alert ("Data Loaded:" + data );
});


. Load ()
Load data from the server and insert the returned HTML code into the matching element.
. Load (url [, data] [, complete (responseText, textStatus, XMLHttpRequest)])
Url: a URL containing the sent request
Key-value pairs after the string sent by data to the server
The callback function of complete when the request is successful.
Usage:
$ ('# Result'). load ('ajax/test.html # iner ');


JQuery. ajax ()
Executes an asynchronous HTTP (ajax) request.
Parameters:
Url type: the request address sent by Sting (the current page by default)
Type: Sting (GET by default) Request Method ("POST" or "GET")
Timeout type: Number indicates the request timeout (in milliseconds). This setting overwrites the global data by default.
Async type: Boolean default setting (true) All requests are one-step requests by default. If you need to synchronize requests, set it to false.
BeforeSend type: Before a function sends 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.
Cache type: Boolean is (true) by default. Setting it to false will not load request information from the browser cache.
Complete type: callback Function after the Function request is complete (called when the request succeeds or fails) parameter: XMLHttpRequest object, success information string. Function (XMLHttpRequest, textStatus) {this; // the options for this ajax request}
The contentType is the content encoding type when the String sends information to the server. The default value is suitable for most applications.
Data Type: the data that the Object String sends to the server. Will be automatically converted to the request string format, after the GET request is appended to the URL
DataType type: the data type expected to be returned by the String server. "xml" indicates that the XML document is returned ." Html "returns plain text information, including script elements ." Script "returns plain text JavaScript code and does not automatically cache the results ." Json "returns a JSON array ." Jsonp "JSONP format.
Error Type: This method is called when a function request fails.
Global: whether a Boolean triggers a global AJAX event. If it is set to true by default, global ajax events are not triggered and can be used to control different AJAX events.
IfModified type: Boolean is set to false by default. New data is obtained only when the server data changes.
ProcessData type: Boolean is (true) by default. By default, the data sent from the sent data will be 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 type: callback Function after the Function request is successful. This method has two parameters: the server returns data and returns the status.
$ (Document). ready (function (){
JQuery ("# clearCac"). click (function (){
JQuery. ajax ({
Url: "/Handle/Do. aspx ",
Type: "post ",
Data: {id: '0 '},
DataType: "json ",
Success: function (msg ){
Alert (msg );
},
Error: function (XMLHttpRequest, textStatus, errorThrown ){
Alert (XMLHttpRequest. status );
Alert (XMLHttpRequest. readyState );
Alert (textStatus );
},
Complete: function (XMLHttpRequest, textStatus ){
This; // The options parameter passed when calling this AJAX request
}
});
});
});


The first parameter XMLHttpRequest returned by the error event has some useful information:
XMLHttpRequest. readyState:

Status Code

0-(not initialized) The send () method has not been called

1-(load) The send () method has been called and a request is being sent.

2-(Loading completed) The send () method is executed completely and all response content has been received

3-(interaction) parse the response content

4-(complete) The response content has been parsed and can be called on the client


XMLHttpRequest. status:
1xx-Information prompt
These status codes indicate temporary responses. Before receiving a regular response, the client should be prepared to receive one or more 1xx responses.
100-continue.
101-switch protocol.
2xx-success
This type of Status Code indicates that the server successfully accepts client requests.
200-OK. The client request is successful.
201-created.
202-accepted.
203-non-authoritative information.
204-NO content.
205-Reset content.
206-part of content.
3xx-redirection
The client browser must perform more operations to implement the request. For example, the browser may have to request different pages on the server or repeat the request through the proxy server.
301-the object has been permanently removed, I .e., permanent redirection.
302-the object has been temporarily moved.
304-not modified.
307-temporary redirection.
4xx-client Error
The client seems to be faulty when an error occurs. For example, the client does not provide valid authentication information for a page that does not exist in a request. 400-Incorrect request.
401-Access denied. IIS defines many different 401 errors, which indicate more specific error causes. These specific error codes are displayed in the browser but not in the IIS log:
401.1-Logon Failed.
401.2-login failed due to server configuration.
401.3-the ACL is not authorized due to resource restrictions.
401.4-filter authorization failed.
401.5-An error occurred while authorizing the ISAPI/CGI application.
401.7-the access is rejected by the URL Authorization Policy on the Web server. This error code is dedicated to IIS6.0.
403-Access prohibited: IIS defines many different 403 errors, which indicate more specific error causes:
403.1-the execution access is forbidden.
403.2-Read access is forbidden.
403.3-write access is forbidden.
403.4-require SSL.
403.5-SSL128 is required.
403.6-the IP address is rejected.
403.7-client certificate required.
403.8-site access is denied.
403.9-too many users.
403.10-the configuration is invalid.
403.11-change the password.
403.12-access to the ing table is denied.
403.13-the client certificate is revoked.
403.14-reject the directory list.
403.15-the access permission of the client is exceeded.
403.16-the client certificate is untrusted or invalid.
403.17-the client certificate has expired or has not yet taken effect.
403.18-the requested URL cannot be executed in the current application pool. This error code is dedicated to IIS6.0.
403.19-CGI cannot be executed for clients in this application pool. This error code is dedicated to IIS6.0.
403.20-logon to Passport failed. This error code is dedicated to IIS6.0.
404-not found.
404.0-(none)-No file or directory found.
404.1-unable to access the Web site on the requested port.
404.2-the Web service extended locking policy blocks this request.
404.3-the MIME ing policy blocks this request.
405-HTTP predicates used to access this page are not allowed (methods are not allowed)
406-the client browser does not accept the MIME type of the requested page.
407-proxy authentication is required.
412-precondition failed.
413-The Request Entity is too large.
414-the request URI is too long.
415-unsupported media type.
416-the requested range cannot be met.
417-execution failed.
423-locking error.
5xx-Server Error
The server cannot complete the request because of an error.
500-internal server error.
500.12-the application is busy restarting on the Web server.
500.13-the Web server is too busy.
500.15-Direct Request to Global. asa is not allowed.
The 500.16-UNC authorization credential is incorrect. This error code is dedicated to IIS6.0.
500.18-the URL-authorized storage cannot be opened. This error code is dedicated to IIS6.0.
500.100-Internal ASP error.
501-the header value specifies the unimplemented configuration.
502-the Web server received an invalid response when used as a gateway or proxy server.
502.1-CGI application timeout.
502.2-CGI application error. Application.
503-the service is unavailable. This error code is dedicated to IIS6.0.
504-gateway timeout.
The 505-HTTP version is not supported.
JQuery. param ()
Create an array, a common object, or a serialized jQuery object, which is used for URL query strings or Ajax requests.
JQuery. param (obj)
Obj is an array used for serialization, a common object, or a jQuery object.
JQuery. param (obj, traditional)
Obj is an array used for serialization, a common object, or a jQuery object.
Traditional
A boolean value indicating whether the traditional "shallow" serialization is performed.
$. Param ({a: [2, 3, 4]}) // "a [] = 2 & a [] = 3 & a [] = 4"
$. Param ({a: {B: 1, c: 2}, d: [3, 4, {e: 5}]}) // "a [B] = 1 & a [c] = 2 & d [] = 3 & d [] = 4 & d [2] [e] = 5"

 

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.