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/03 Report--
This article mainly explains "the function, advantages and disadvantages and example usage of Ajax in js". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the role, advantages and disadvantages and example usage of Ajax in js".
Ajax summary in js.
I. the role of Ajax:
1. Is to let js read the data on the server.
two。 Read the data on the server without refresh, for example, verify that the account and password are correct.
(1) advantages of ajax:
1. Reduce the burden of redundant requests and responses on the service.
two。 Update the page without refreshing to bring a better user experience.
3. Reduce the burden of server sketches, save space and broadband rental costs.
4. The use of asynchronous submission, read and write faster.
(2) the disadvantages of ajax:
1.AJAX makes extensive use of javascript and ajax engines, depending on browser support. Consider the compatibility with the browser when writing
AJAX is only a partial refresh, so the back button on the page is useless.
The support of streaming media and mobile devices is not very good, etc.
two。 The difference between Get and Post:
Get method: common form submission method: submit the value after url;? Name = value & name = value box.
Example of submitting a form:
Name:
Password:
Difference:
1.get is used to transmit data through URL, and post is transmitted through Content in http.
2.get capacity is small, not suitable to transfer big data, (general 4k-10k), post mode capacity is relatively large, the general server can reach 2G capacity.
3. For files that are too large, they will not go to post, go to controls.
4.get way security is poor, post is relatively better, a bunch of security can only go https.
There is a cache in 5.get mode, but not in post. Get is more suitable for obtaining data from the server, and post is more suitable for passing data to the server.
Three: write an Ajax:
1. Create an ajax object
two。 Link to server
3. Send a request
4. Receive return value
(1) create an ajax object
Var oAjax = new XMLHttpRequest () / / does not support IE6
Var oAjax = new ActiveXObject ("microsoft.XMLHTTP"); / / IE6 is supported
Resolve compatibility: if (window.XMLHttpRequest) {var oAjax = new XMLHttpRequest () } else {var oAjax = new ActivexObject ("Microsoft.XMLHTTP")} Why should we use window.XMLHttpRequest as a parameter? it should be a condition for direct XMLHttpRequest. IE6 will report an error directly, but if XMLHttpRequest is taken as an attribute, IE will only report that undefined just meets our condition. (2) oAjax.open ('Get',url,true) synchronization of linked servers: step by step. Async: multiple things come together. (3) send a request oAjax.send (); (4) accept and return oAjax.onreadystatechange = function () {/ / where has the browser and server gone? If (oAjax.readyState==4) / / read completed {if (oAjax.status==200) / / read succeeded {fnSuccess (oAjax.responseText)} else if (fnfaild) {fnfaild (oAjax.status);}}
Readystatus description
0 (uninitialized) has not yet called the open () method
1 (load) how to send a request when calling the send () method
2 (load completed) the send () method is completed, and all the response contents have been received.
3 (parsing) parsing response content
4 (complete) the parsing of the response content is complete, and the client can call the
Synchronous request: after the request occurs, you have to wait for the server to finish executing the current code.
Asynchronous request: after the request occurs, you can continue to execute the current code without waiting for the server to finish executing. At this point, I believe you have a deeper understanding of the role, advantages and disadvantages and example usage of Ajax in js, so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.