Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Weather Forecast function of AJAX

Shulou Source: shulou.com Published: 2022-06-03 16:41:12 10月04日 Update

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!

Tags: Function Weather Weather Forecast Forecast Server Learning Service data more browser help Browse next function region at the same time character string number of times status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn NVidia Shulou Technology Shulou Information