jquery Operations Ajax Method Summary _jquery

Source: Internet
Author: User
Tags getscript http post http request string format browser cache

The Ajax () method loads remote data through an HTTP request.

The approach is the jQuery-bottom AJAX implementation. Simple and easy-to-use high-level implementation see $.get, $.post, etc. $.ajax () returns the XMLHttpRequest object that it created. Most of the time you don't have to manipulate the function directly, unless you need to manipulate the infrequently used options for more flexibility.

In the simplest case, $.ajax () can be used directly without any parameters.

Note: All options can be set globally through the $.ajaxsetup () function.

Grammar

Jquery.ajax ([Settings])

Parameters Description
Settings

Optional. A collection of key-value pairs used to configure AJAX requests.

You can set the default value for any option by $.ajaxsetup ().

Jquery.get ()

Loads data from the server using an HTTP GET request.

Jquery.get (URL [, data] [, Success (DATA,TEXTSTATUS,JQXHR)] [Dtatype])

URL a URL that contains the request to send
Data sent to the server by the string after the key value pair
Success () callback function when a request succeeds
DataType the expected data returned from the server.

  Usage:

$.get ("test.cgi", {name: "John", Time: "2pm"},
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 that contains the request to send
Data sent to the server by the string after the key value pair
Success () callback function when a request succeeds

Jquery.getscript ()

Loads and executes a JavaScript file from the server using an HTTP GET request.
Jquery.getscript (Url[success (SCRIPT,TEXTSTATUS,JQXHR))
URL a URL that contains the request to send
Data sent to the server by the string after the key value pair

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 performed. ');
});

Jquery.post ([Settings])

Loads data from the server using an HTTP POST request.
Jquery.post (url[,data][,success (DATA,TEXTSTATUS,JQXHR)][,datatype])
URL a URL that contains the request to send
Data sent to the server by the string after the key value pair
Success () callback function when a request succeeds

Usage:

$.post ("test.php", {name: "John", Time: "2pm"},
function (data) {
alert ("Data Loaded:" + data); 
   });

. Load ()

Loads the data from the server and inserts the returned HTML code into the matching element.

. Load (Url[,data][,complete (responsetext,textstatus,xmlhttprequest)])
URL a URL that contains the request to send
Data sent to the server by the string after the key value pair
Complete the callback function when the request succeeds

Usage:

$ (' #result '). Load (' ajax/test.html #container ');

Jquery.ajax ()

Executes an asynchronous HTTP (Ajax) request.

Parameters:

URL type: Sting send the requested address (default current page)
Type: Sting (default to Get) Request method ("POST" or "get")
Timeout Type: Number sets the request timeout (milliseconds), which overrides the global by default.
Async type: Boolean default setting (TRUE) all requests are a one-step request under the default settings, and set to False if a synchronization request is required.
Beforesend Type: Function that modifies the XMLHttpRequest object before the request can be sent, such as adding a custom HTTP header. The XMLHttpRequest object is the only parameter.
Cache type: Boolean default (True) set to False will not load request information from the browser cache.
Complete type: callback function after a function request completes (calls are made when the request succeeds or fails): XMLHttpRequest object, Success message string. function (XMLHttpRequest, textstatus) {this;//the options for this AJAX request}
The ContentType type is: String the content encoding type when sending information to the server, and the default value is suitable for most applications.
Data type: Object String that is sent to the server. is automatically converted to the request string format, and the GET request is appended to the URL
DataType type: String expects the data type returned by the server, and "XML" returns the XML document. "HTML" returns plain text information containing the script element. Script returns the 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 type: Boolean triggers global AJAX events. The default (TRUE) setting to false will not trigger global AJAX events and can be used to control different AJAX events.
Ifmodified type: Boolean defaults to False to get new data only when server data changes.
ProcessData type: Boolean defaults to (true) by default, the data sent by the sent data will be converted to an object (technically not a string) to match the default content type "Application/x-www-form-urlencod Ed ". Set to False if you want to send DOM tree information or other information that you do not want to convert.
Success Type: callback function when function request succeeds. This method has two parameters: the server returns the data and returns the status.

$ (document). Ready (function () {
jQuery ("#clearCac"). Click (function () {
jquery.ajax ({
URL: "/h Andle/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 parameters that are passed when the AJAX request is invoked
}
   });
});
});

The first argument returned by the error event XMLHttpRequest some useful information:

Xmlhttprequest.readystate:

  Status code

0-(uninitialized) the Send () method has not been called

1-(load) called Send () method, sending request

2-(load complete) Send () method completed, received all response content

3-(interactive) parsing response content

4-(complete) The response content resolution is complete and can be invoked on the client

Xmlhttprequest.status:

1xx-Information Tips
These status codes represent a temporary response. The client should be prepared to receive one or more 1xx responses before receiving a regular response.
100-Continue.
101-Switch protocol.
2xx-success
This type of status code indicates that the server successfully accepted the client request.
200-OK. The client request was successful.
201-created.
202-accepted.
203-Non-authoritative information.
204-no content.
205-Reset the content.
206-part content.
3xx-redirect
The client browser must take more action to implement the request. For example, a browser might have to request a different page on the server, or repeat the request through a proxy server.
301-The object has been permanently removed, that is, permanent redirection.
302-The object has been temporarily moved.
304-not modified.
307-Temporary redirection.
4xx-Client Error
An error occurred and the client appears to have a problem. For example, a client requests a page that does not exist, and the client does not provide valid authentication information. 400-the wrong request.
401-access is denied. IIS defines a number of different 401 errors that indicate a more specific cause of the error. These specific error codes are displayed in the browser but are not displayed in the IIS log:
401.1-Login failed.
The 401.2-server configuration caused the login to fail.
401.3-Authorization is not granted due to ACL restrictions on resources.
401.4-Filter Authorization failed.
401.5-ISAPI/CGI application authorization failed.
401.7– access is denied by the URL authorization policy on the Web server. This error code is dedicated to IIS6.0.
403-Prohibit access: IIS defines a number of different 403 errors that indicate a more specific cause of the error:
403.1-execution access is prohibited.
403.2-Read access is prohibited.
403.3-Write access is prohibited.
403.4-Require SSL.
403.5-Request SSL128.
The 403.6-IP address was rejected.
403.7-Client certificate required.
403.8-site access is denied.
403.9-Excessive number of users.
403.10-Configuration is not valid.
403.11-Password change.
403.12-access to the mapping table is denied.
403.13-The client certificate was revoked.
403.14-Deny directory list.
403.15-Client access permission exceeded.
403.16-Client certificate is not trusted 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 performed for clients in this application pool. This error code is dedicated to IIS6.0.
403.20-passport Login failed. This error code is dedicated to IIS6.0.
404-not found.
404.0-(None) – No files or directories found.
404.1-The Web site cannot be accessed on the requested port.
The 404.2-web service extension lockout policy blocks this request.
The 404.3-mime mapping 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-Prerequisite failed.
The 413– request entity is too large.
414-The request URI is too long.
415– media type that is not supported.
416– the requested range is not satisfied.
417– execution failed.
423– the locked error.
5xx-Server Error
The server was unable to complete the request due to an error encountered.
500-Internal server error.
The 500.12-application is busy restarting on the Web server.
The 500.13-web server is too busy.
500.15-Direct Request Global.asa is not allowed.
The 500.16–unc authorization credentials are incorrect. This error code is dedicated to IIS6.0.
The 500.18–url authorization store cannot be opened. This error code is dedicated to IIS6.0.
500.100-Internal ASP error.
501-The header value specifies a configuration that is not implemented.
An invalid response was received when the 502-web server was used as a gateway or proxy server.
The 502.1-cgi application timed out.
Error 502.2-cgi application. Application.
503-The service is not available. This error code is dedicated to IIS6.0.
The 504-gateway timed out.
505-http version is not supported.
Jquery.param ()
Creates an array, an ordinary object, or the serialized representation of a jquery object, used for URL query strings or AJAX requests.
Jquery.param (obj)
Obj an array to serialize, an ordinary object, or a jquery object.
Jquery.param (obj, Traditional)
Obj an array to serialize, an ordinary object, or a jquery object.
Traditional
A Boolean value that indicates 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.