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

How to realize the Weather Forecast function of AJAX

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to achieve the weather forecast function of AJAX". In the daily operation, I believe many people have doubts about how to achieve the weather forecast function of AJAX. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to achieve the weather forecast function of AJAX". Next, please follow the editor to study!

The code is as follows:

Untitled document

Function $() {

Return document.getElementById (arguments [0])

}

Function btnSty (objId,objStyle)

{

$(objId) .style.display = objStyle

}

/ / prompt window control

Function ifodis () {

BtnSty ('loadifo','none')

}

Function settime (a) {

SetTimeout (a dint 1000)

}

Function loadtime () {

$("loadifo") [xss_clean] + = "."

}

/ / XML data binding

Var xmldoc = false

Function loadurl (n) {

/ / generate random numbers and limit the number of refreshes

Var now=new Date ()

Var Num=now.valueOf ()

/ / define address parameters

Url = "weather.asp?n=" + n + "& id=" + Num

/ / defined as asynchronous transfer mode

Xmldoc = false

/ / XMLHttp classes that need to be created for browsers such as Mozill,Safari

If (window.XMLHttpRequest) {

Xmldoc = new XMLHttpRequest ()

If (xmldoc.overrideMimeType) {

Xmldoc.overrideMimeType ('text/xml')

}

}

/ / XMLHttp class created in IE browser

Else if (window.ActiveXObject) {

Try {

Xmldoc = new ActiveXObject ("Msxml3.XMLHTTP")

}

Catch (e) {

Try {

Xmldoc = new ActiveXObject ("Msxml2.XMLHTTP")

}

Catch (e) {

Try {

Xmldoc = new ActiveXObject ("Microsoft.XMLHTTP")

}

Catch (e) {}

}

}

}

/ / returned if the XMLHTTP class cannot be created

If (! Xmldoc) {

Return false

}

/ / call the CheckState function

Xmldoc.onreadystatechange = CheckState

Xmldoc.open ('GET',url,true)

Xmldoc.send (null)

}

/ / status detection

Function CheckState () {

BtnSty ('loadifo','')

/ / receive a complete server response

If (xmldoc.readyState = = 1) {

$("loadifo") [xss_clean] = "connect to the server"

}

Else if (xmldoc.readyState = = 2) {

$("loadifo") [xss_clean] = "start loading data"

}

Else if (xmldoc.readyState = = 3) {

$("loadifo") [xss_clean] = "loading data"

Settime (loadtime)

}

Else if (xmldoc.readyState = = 4) {

/ / the HTTP server response value was successful

If (xmldoc.status = = 200) {

/ / write the string returned by the server to the area of the page where ID is showdiv

$("loadifo") [xss_clean] = "loading completed"

Var response = xmldoc.responseText

Settime (ifodis)

$("prolist") [xss_clean] = response

}

Else {

$("loadifo") [xss_clean] = "error" + xmldoc.statusText+ "Please reselect"

}

}

}

Wuhan

Nanchang

Haikou

Beijing

Shanghai

Guangzhou

Yinchuan

Zhengzhou

Changsha

Hangzhou

Hong Kong

Xi'an

Chengdu

Qingdao

Guiyang

Jinan

Hefei

Fuzhou

Nanjing

Milan

At this point, the study on "how to achieve the weather forecast function of AJAX" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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