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 Communication principle XMLHttpRequest

2025-01-17 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 communication principles XMLHttpRequest", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn the "Ajax communication principles XMLHttpRequest example analysis" this article.

Obviously, AJax is a technology that uses JavaScript scripts to access data.

AJAX enables web pages to be updated asynchronously. This is to make a partial update to the page without reloading the entire page.

XMLHttpRequest is the key to AJAX

Browsers now support XMLHttpRequest objects (IE5 and IE6 use ActiveXObject).

There are five states of readyState for requesting data from the background: server is not initialized, 1: server connection has been established, 2 requests have been accepted, 3 requests are being processed, 4 requests are completed.

Every time you change the state, you can trigger an onreadystatechange event. Status has two states: 200,404: page not found.

Let's take a look at an Ajax foreground implementation code:

The copy code is as follows:

Untitled page

Function getName () {

Var xmlhttp

If (window.XMLHttpRequest) {

Xmlhttp=new XMLHttpRequest ()

} else {

Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP")

}

Xmlhttp.onreadystatechange=function () {

If (xmlhttp.readyState==4 & & xmlhttp.status==200) {

Alert ("Hello:" + xmlhttp.responseText)

}

}

Xmlhttp.open ("post", "Default.aspx?id=gname", true)

Xmlhttp.send ()

}

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