URL: String-type parameter (the current page address by default.
Type: a parameter of the string type. The request method (post or get) is get by default. Note other HTTP request methods, such as put and
Delete can also be used, but only some browsers support it.
Timeout: a parameter of the number type is required. Set the request timeout time (in milliseconds ). This setting overwrites the global settings of the $. ajaxsetup () method.
.
Async: A boolean parameter. The default value is true. All requests are asynchronous requests.
To send a synchronization request, set this option to false. Note: Synchronous requests will lock the browser and other user operations are required.
The request can be executed only after the request is complete.
Cache: A boolean parameter. The default value is true. When datatype is script, the default value is false ).
Setting false does not load request information from the browser cache.
Data: data sent to the server using an object or string parameter. If it is no longer a string, it is automatically converted to a string
. The GET request will be appended to the URL. To prevent this automatic conversion, you can view the processdata option. The object must be in the key/value format.
Format. For example, {foo1: "bar1", foo2: "bar2"} is converted to & foo1 = bar1 & foo2 = bar2. If it is an array, jquery will automatically be different
The value corresponds to the same name. For example, {FOO: ["bar1", "bar2"]} is converted to & Foo = bar1 & Foo = bar2.
Datatype: it must be a string type parameter. The data type returned by the server is expected. If this parameter is not specified, jquery automatically uses the http package mime
Responsexml or responsetext is returned and passed as the callback function parameter.
The available types are as follows:
XML: the XML document is returned and can be processed by jquery.
HTML: returns plain text HTML information. The included script tag is executed when the Dom is inserted.
Script: returns plain text JavaScript code. Results are not automatically cached. Unless the cache parameter is set. Note that in the remote request
All post requests are converted to GET requests.
JSON: Return JSON data.
Jsonp: jsonp format. When a function is called in the form of sonp, such as myurl? Callback = ?, Jquery will automatically Replace the last
"?" For the correct function name to execute the callback function.
Text: returns a plain text string.
Beforesend: a parameter of the function type. Before sending a request, you can modify the function of the XMLHTTPRequest object, for example, adding a custom
HTTP header. In beforesend, if false is returned, the Ajax request can be canceled. The XMLHTTPRequest object is the only parameter.
Number.
Function (XMLHttpRequest ){
This; // The options parameter passed when calling this Ajax request
}
Complete: a parameter of the function type. It is the callback function called after the request is complete (all calls are called when the request is successful or fails ).
Parameter: XMLHTTPRequest object and a string that describes the successful request type.
Function (XMLHttpRequest, textstatus ){
This; // The options parameter passed when calling this Ajax request
}
Success: Required parameter of the function type. The callback function called after the request is successful has two parameters.
(1) data returned by the server and processed according to the datatype parameter.
(2) A string describing the status.
Function (data, textstatus ){
// Data may be xmldoc, jsonobj, HTML, text, etc.
This; // The options parameter passed when calling this Ajax request
Error: Required parameter of the function type. The function called when the request fails. This function has three parameters: XMLHTTPRequest object and error
Optional ).
Ajax event functions are as follows:
Function (XMLHttpRequest, textstatus, errorthrown ){
// Generally, textstatus and errorthrown only contain one of the information.
This; // The options parameter passed when calling this Ajax request
}
Contenttype: String-type parameter. When the message is sent to the server, the content encoding type is default.
Is "application/X-WWW-form-urlencoded ". This default value is suitable for most applications.
Datafilter: a function that requires function-type parameters to pre-process the original data returned by Ajax.
Provides two parameters: Data and type. Data is the original data returned by Ajax, and type is provided when jquery. Ajax is called.
Datatype parameter. The value returned by the function will be further processed by jquery.
Function (data, type ){
// Return the processed data
Return data;
}
Global: A boolean parameter. The default value is true. Indicates whether to trigger a global Ajax event. Setting this parameter to false does not trigger global events.
Ajax events, such as ajaxstart or ajaxstop, can be used to control various Ajax events.
Ifmodified: A boolean parameter. The default value is false. Obtain New data only when the server data changes.
The server data change judgment is based on the last-modified header information. The default value is false, indicating that the header information is ignored.
Jsonp: a parameter of the string type. In a jsonp request, rewrite the name of the callback function.
This value is used to replace "Callback =? "Callback" in the URL parameter in this get or POST request, for example
{Jsonp: 'onjsonpload'} causes "onjsonpload =? "To the server.
Username: a string-type parameter that is used to respond to an HTTP access authentication request.
Password: a string-type parameter used to respond to an HTTP access authentication request.
Processdata: A boolean parameter. The default value is true. By default, the sent data is converted to an object (technically
It is not a string) to use with the default content type "application/X-WWW-form-urlencoded ". If you want to send Dom
Set the tree information or other information that you do not want to convert to false.
Scriptcharset: a string-type parameter. Only when the datatype is "jsonp" or "script" and the type is get
Is used to forcibly modify the character set (charset ). Generally, the local and remote content encoding is not used at the same time.
Case code:
$ (Function () {$ ('# send '). click (function () {$. ajax ({type: "Get", URL: "test. JSON ", data: {Username: $ (" # username "). val (), content: $ ("# Content "). val ()}, datatype: "JSON", success: function (data) {$ ('# restext '). empty (); // clear all content in restext var html = ''; $. each (data, function (commentindex, comment) {HTML + = '<Div class = "comment"> <H6>' + comment ['username'] + ': </H6> <P class = "para" '+ comment ['content'] +' </P> </div> ';}); optional ('{restext'{.html (HTML );}});});});