In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what the attributes of ajax are. It is very detailed and has a certain reference value. Friends who are interested must finish it!
The properties of ajax are: url, type, timeout, async, beforeSend, cache, data, complete, success, error, contentType, dataFilter, global, jsonp, and so on.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Detailed description of the properties of ajax
1 、 url:
Requires a parameter of type String (the default is the current page address) to send the requested address.
There is generally no Chinese in url, whether it is a link or a value!
2 、 type:
A parameter of type String is required, and the request method (post or get) defaults to get. Note that other http request methods, such as put and delete, can also be used, but only some browsers support them.
3 、 timeout:
Requires a parameter of type Number to set the request timeout (in milliseconds). This setting overrides the global setting of the $.ajaxSetup () method.
4 、 async:
A parameter of type Boolean is required. The default setting is true. All requests are asynchronous requests. If you need to send a synchronization request, set this option to false. Note that the synchronization request locks the browser, and the user must wait for the request to complete before performing other actions.
5 、 cache:
A parameter of type Boolean is required. The default is true (when dataType is script, the default is false). Setting to false will not load the request information from the browser cache.
6 、 data:
Data sent to the server is required for parameters of type Object or String. If it is no longer a string, it is automatically converted to string format. The get request will be appended to the url. To prevent this automatic conversion, you can check the processData option. The object must be in key/value format, such as {foo1: "bar1", foo2: "bar2"} converted to & foo1=bar1&foo2=bar2. If it is an array, JQuery automatically corresponds to the same name for different values. For example, {foo: ["bar1", "bar2"]} is converted to & foo=bar1&foo=bar2.
If you want to pass the Chinese value to the background, you need to fill in the attribute contentType: "application/x-www-form-urlencoded;charset=UTF-8"
Type must be post (writing get at type will not make an error when passing English, so this should be noted)
7 、 dataType:
Requires a parameter of type String, the type of data expected to be returned by the server. If not specified, JQuery automatically returns responseXML or responseText based on the http package mime information and passes it as a callback function parameter. The available types are as follows:
Xml: returns the XML document, which can be processed with JQuery.
Html: returns plain text HTML information; the included script tag is executed when the DOM is inserted.
Script: returns plain text JavaScript code. The results are not automatically cached. Unless the cache parameter is set. Note that when a remote request is made (not under the same domain), all post requests will be converted to get requests.
Json: returns JSON data.
Jsonp:JSONP format. When calling a function in the form of SONP, for example, myurl?callback=?,JQuery will automatically replace the latter "?" Is the correct function name to execute the callback function.
Text: returns a plain text string.
8 、 beforeSend:
It is required to be a parameter of type Function. You can modify the function of the XMLHttpRequest object before sending the request, such as adding a custom HTTP header. If false is returned in beforeSend, you can cancel this ajax request. The XMLHttpRequest object is the only parameter.
Function (XMLHttpRequest) {this; / / the options parameter passed when this ajax request is called}
9 、 complete:
A parameter of type Function is required, and the callback function is called after the request is completed (called when the request succeeds or fails). Parameters: the XMLHttpRequest object and a string that describes the type of successful request.
Function (XMLHttpRequest, textStatus) {this; / / the options parameter passed when this ajax request is called}
10 、 success:
A parameter of type Function is required. The callback function called after a successful request has two parameters.
(1) the data returned by the server and processed according to dataType parameters.
(2) A string that describes the status.
Function (data, textStatus) {/ / data may be the options parameter passed when xmlDoc, jsonObj, html, text, etc. This; / / calls this ajax request.
11 、 error:
Requires a parameter of type Function, the function to be called when the request fails. This function takes three parameters, namely, the XMLHttpRequest object, the error message, and the captured error object (optional). The ajax event function is as follows:
Function (XMLHttpRequest, textStatus, errorThrown) {/ / normally only one of textStatus and errorThrown contains information this; / / the options parameter passed when this ajax request is called}
12.contentType:
A parameter of type String is required, and the content encoding type defaults to "application/x-www-form-urlencoded" when sending information to the server. This default value is suitable for most applications.
When the data format sent is json, the encoding type is set to: "application/json; charset=utf-8"
13 、 dataFilter:
A function that requires a parameter of type Function to preprocess the raw data returned by Ajax. Provide two parameters, data and type. Data is the raw data returned by Ajax, and type is the dataType parameter provided when jQuery.ajax is called. The value returned by the function will be further processed by jQuery.
Function (data, type) {/ / returns the processed data return data;}
14 、 dataFilter:
A function that requires a parameter of type Function to preprocess the raw data returned by Ajax. Provide two parameters, data and type. Data is the raw data returned by Ajax, and type is the dataType parameter provided when jQuery.ajax is called. The value returned by the function will be further processed by jQuery.
Function (data, type) {/ / returns the processed data return data;}
15 、 global:
A parameter of type Boolean is required, and the default is true. Indicates whether a global ajax event is triggered. Setting to false will not trigger global ajax events, and ajaxStart or ajaxStop can be used to control various ajax events.
16 、 ifModified:
A parameter of type Boolean is required, and the default is false. Get new data only when the server data changes. The judgment of server data change is based on Last-Modified header information. The default value is false, which ignores header information.
17 、 jsonp:
The name of the callback function is overridden in an jsonp request if it is required to be a parameter of type String. This value is used instead of in "callback=?" The "callback" part of the URL parameter in such a GET or POST request, such as {jsonp:'onJsonPLoad'}, results in a "onJsonPLoad=?" Pass it to the server.
18 、 username:
A parameter of type String required to respond to the user name of the HTTP access authentication request.
19 、 password:
A parameter of type String is required for the password used in response to the HTTP access authentication request.
20 、 processData:
A parameter of type Boolean is required, and the default is true. By default, the data sent is converted to an object (not a string technically) to match the default content type "application/x-www-form-urlencoded". If you want to send DOM tree information or other information that you do not want to convert, set it to false.
21 、 scriptCharset:
A parameter of type String is required, which is used to force the modification of the character set (charset) only if the dataType is "jsonp" or "script" at the time of the request, and type is GET. Local and remote content encoding is usually not used at the same time. (if you want to see more, go to the AJAX development manual section.)
The each () method of the Jquery object is as follows: 22. By the way, the $.each () function:
The $.each () function is different from the each () method of the JQuery object. It is a global function that does not manipulate the JQuery object, but takes an array or object as the first argument and a callback function as the second argument. The callback function has two parameters: the first is the index of the object's member or array, and the second is the corresponding variable or content. The example of $.each () is as follows:
$("button") .click (function () {$("li") .each (function () {alert ($(this). Text ()});})
Index-index location of the selector Note: function (index,element)
Element-current element (you can also use the "this" selector)
The above is all the content of this article "what are the attributes of ajax?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.