Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of ajax request Technology

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "sample Analysis of ajax request Technology", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "sample Analysis of ajax request Technology".

1. Write at the front:

Reading requirements:

Have some basic knowledge of HTML, CSS, JavaScript and Json

two。 What is ajax?

Ajax: that is, "Asynchronous Javascript And XML" (asynchronous JavaScript and XML), refers to a web page development technology that creates interactive web applications.

3. Why use ajax

In the dynamic web page development technology, the data interaction between the client (usually the browser) and the server is very frequent, how to save network resources and provide a good user experience is very critical. Ajax uses asynchronous request mode, which makes it possible to exchange data with the background without refreshing the entire page, thus updating the content.

4. How to use native ajax

The key point of using ajax technology falls on the XMLHttpRequest (note: ie5, ie6 uses ActiveXObject) object, so making good use of this object is the key.

Note:

Function loadData () {/ / create XMLHttpRequest object var xmlHttpRequestObj = {}; / / create json object, transfer json format data to server Var jsonObj = {}; if (window.XMLHttpRequest) {/ / IE7+, Firefox, Chrome, Opera, Safari xmlHttpRequestObj = new XMLHttpRequest ();} else {/ / IE6, IE5 xmlHttpRequestObj = new ActiveXObject ("Microsoft.XMLHTTP") } / / when the request state changes, the xmlHttpRequestObj .onreadystatechange method xmlHttpRequestObj .onreadystatechange = function () {if (xmlHttpRequestObj.readyState = = 0) {Alert ("open () function not executed");} else if (xmlHttpRequestObj.readyState = = 1) {Alert ("open () function executed, send () function not executed") } else if (xmlHttpRequestObj.readyState = = 2) {Alert ("send () function executed, header and status code can be obtained")} else if (xmlHttpRequestObj.readyState = = 3) {Alert ("header received, parsing response body");} else if (xmlHttpRequestObj.readyState = = 4) {Alert ("request completed") If (xmlHttpRequestObj.status = = 200) {Alert ("response ready, deserialize json object fill data to the page");} else if (xmlHttpRequestObj.status = = 400) {Alert ("page loss");} else {Alert ("service exception") }} / / method: request method: GET, POST, PUT, DELETE... Url: the requested address asnyc: whether to use asynchronous xmlHttpRequestObj.open ("method", "url", async); / / set the request header. The POST request format needs to be loaded, while the other requests do not require xmlHttpRequestObj.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); / / request data. The parameter is jsonObj json object xmlHttpRequestObj.send (jsonObj). } the above is all the content of the article "sample Analysis of ajax request Technology". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report