In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shares with you the content of a sample analysis of the $. Ajax () method parameters. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Ajax concept
AJAX, namely "Asynchronous Javascript And XML" (Asynchronous JavaScript and XML), refers to a web page development technology that creates interactive web page applications.
AJAX = Asynchronous JavaScript and XML (a subset of the standard generic markup language).
AJAX is a technology for creating fast dynamic web pages.
By exchanging a small amount of data with the server in the background, AJAX can update web pages asynchronously. This means that some part of the page can be updated without reloading the entire page.
Traditional web pages (without AJAX) if you need to update the content, you must reload the entire web page.
Ajax method
The $.ajax () method is the lowest Ajax implementation of jQuery. Its structure is as follows:
$.ajax (options)
This method has only one parameter, but this object contains information such as the request settings and callback functions required by the $.ajax () method. The parameters are in the form of key/value, and all parameters are optional. Common parameters are shown in the following table:
1.url
Requires a parameter of type String (the default is the current address) to send the requested page.
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 synchronize requests, 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 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 not 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.
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 mine information of the HTTP package 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. 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:JSON format. When calling a function in the form of JSONP, 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) {options parameter passed when this;// calls this ajax request}
9.complete
A parameter of type Function is required, and the callback function is called after the request is completed (whether 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 and other this; / / call 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 the 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 when information is sent to the server. The content encoding type defaults to "application/x-www-form-urlencoded". This default value is suitable for most applications.
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) {/ / return the processed data return data;}
14.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 and ajaxStop can be used to control various ajax events.
15.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.
16.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.
17.username
A parameter of type String is required for users who respond to HTTP access authentication requests.
18.password
A parameter of type String is required for the password used in response to the HTTP access authentication request.
19.processData
A parameter of type Boolean is required, and the default is true. By default, the data sent is converted to an object (technically, not a string) 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.
20.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.
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 the contents of resText var html ='' $.each (data, function (commentIndex, comment) {html + =''+ comment ['username'] +':
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.