java zero to one: Jquery - 3: JQuery support of ajax

Use jQuery for ajax js use less verbose compared to it, thinking more clearly, the actual development, mostly using ajax by jquey.

$ .Ajax method:

$ .Ajax method there are many parameters can be used, but I am here to write yourself a few commonly used parameters:

1.url:

Requirements for the type String parameter (the default address of this page) address of the request.

2.timeout:

Number parameter type requirements, set request time (in milliseconds). This setting overrides $ .ajaxSetup () method of the global settings.

3.data:

Sending the server an additional request data, GET request will be those requests appended to the url, the object must key / value format, e.g. {foo1: "bar1", foo2: "bar2"} is converted to & foo1 = bar1 & foo2 = bar2. If the array, JQuery will automatically correspond to the same name to different values. For example {foo: [ "bar1", "bar2"]} is converted to & foo = bar1 & foo = bar2.

4.dataType:

Specify the return data type, available xml, html, script, json, jsonp, text;

 5.success:

Function requirements for the type of parameters, the callback function to call when the request is successful, there are two parameters.
(1) returned by the server, and performs data processing in accordance with the dataType parameter.
String (2) described state.
 function (Data, textStatus) {
       // Data may be xmlDoc, jsonObj, html, text like
       this; options // call parameters passed when this ajax request
}

6.error

Function type parameter is required, the function is called when the request fails. This function takes three parameters, i.e., XMLHttpRequest object, an error message, error trapping object (optional). ajax event function is as follows:
       function (the XMLHttpRequest, textStatus, errorThrown) {
         

Guess you like

Origin blog.csdn.net/kerryqpw/article/details/104089984