In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the example usage of ajax in JavaScript". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the example usage of ajax in JavaScript".
(1) $.load (url, [data], [callback])
Function: load the specified resource to write to the current page
Example:
$(function () {$("body # D1"). Load ("2.html"); alert ($("html now"). Html (); $("# b1") .click (function () {alert ($("html"). Html ();});}))
Html:
1.html:
Insert title here1111111111
2.html
Insert title here22222
Get (url, [data], [callback])
Function: send a get request to the server:
("button") .click (function () {$.get ("demo_ajax_load.txt", function (result) {$("div") .html (result);});})
$.post (url, [data], [callback])
Function: ditto
$.getJSON (url, [data], [callback])
Function: same as above, except that the loaded data is json data
GetJSON ("test.js", function (json) {alert ("JSON Data:" + json.users [3] .name);})
$.getScript (url, [callback])
Function: load js data from the specified url and execute
Example (from w3school)
$.Ajax (options):
Detailed description of parameters:
Async://Boolean type this key-value pair is true by default, that is, an asynchronous request (partial refresh). If set to false, it will become a synchronous request, then the browser will be locked and the user cannot perform other operations on it, and will not be unlocked until the request is completed. Global (Boolean type) / / indicates whether the global is triggered. The default is true. The global setting of Ajax will be described in later chapters. Setting global means that all Ajax will be able to use this global content, for example, all Ajax events will trigger the same path. Type (String): / / (default: "GET") request method ("POST" or "GET"), default is "GET". Note: other HTTP request methods, such as PUT and DELETE, can also be used, but only some browsers support them. Cache: (Boolean type) / / setting false will not load information from the browser cache for jQuery1.2 or later. ContentType: (String type) / / is used to set the encoding format. The default format is "application/x-www-form-urlencoded"), which is generally recommended. IfModified (Boolean): / / (default: false) gets new data only when the server data changes. ProcessData (Boolean): / / (default: true) by default, the data sent is converted to an object. Timeout (Number): / / sets the request timeout (milliseconds). This setting is a global setting. DataType: (String type) / / is used to set the data type returned by the server, but the content is also limited. The available values are as follows: ┠ xml / / set this value to XML documents on the server side. If you know more about Ajax, I think you all know what the x stands for in Ajax, right? Therefore, it is called A (Asynchronous) j (javascript) a (and) x (xml) ┠ html / / server returns a document in HTML format (according to personal understanding, if xml represents x according to the above understanding, then this type means ajah). The ┠ script / / server returns a script that is [plain text] and will not be executed or calculated. ┠ json / / returns the document in Json format ┠ text / / returns plain text ┗ jsonp / / JSONP is an unofficial protocol that allows integration of Script tags on the server side to return to the client, and cross-domain access in the form of javascript callback. For example, users want to get ["kwoojan", "KwooShung"] If jsonp is set, the server will return callbackFunction (["kwoojan", "KwooShung"]) data (type String) / / this method is critical and is mainly used to send data to the server. The format is a key-value pair, such as userName=CSS Learning Network & Address= http://www.cssxuexi.cn/, then the corresponding value received by the server is CSS Learning Network url (String): / / (default: current page address) to send the request address, that is, your data data needs to be processed. BeforeSend (function) / / this key is a function method, which is called before you send a request. For example, when the user performs an action, similar words such as "loading, please wait" are displayed on the page. In most cases, this key-value pair is used to give a user-friendly prompt. Success (Function) / / this method is called when the Ajax request is successful and is typically used to parse the data returned by the server. This method is called when error (Function) / / fails. Complete (Function) / / call this method when the Ajax request is complete
Accompanied by a specific example:
Function reg () / / Register {$.ajax ({type: "POST", cache:false, url: "servlet/UserServer", dataType: "json", data: "class=reg&userName=" + $("# userName"). Val () + "& userPwd=" + $("# userPwd"). Val () Success: function (data) {alert (data.info) }, error:function () {alert ("failed to access data!") Thank you for reading. The above is the content of "example usage of ajax in JavaScript". After the study of this article, I believe you have a deeper understanding of the example usage of ajax in JavaScript, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.