AJAX weather forecast front-end

Source: Internet
Author: User

You can directly use the background program to capture weather information across domains.
Currently, firefox is fully supported. Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
<Script language = "JavaScript" type = "text/javascript">
Function $ (){
Return document. getElementById (arguments [0])
}
Function btnSty (objId, objStyle)
{
$ (ObjId). style. display = objStyle
}
// Prompt window control
Function ifodis (){
BtnSty ('loadifo', 'None ');
}
Function settime (){
SetTimeout (a, 1000 );
}
Function loadtime (){
$ ("Loadifo"). innerHTML + = "."
}
// XML Data Binding
Var xmldoc = false;
Function loadurl (n ){
// Generate a random number and limit the number of refreshes
Var now = new Date ();
Var Num = now. valueOf ();
// Define the forward Parameters
Url = "weather. asp? N = "+ n +" & id = "+ Num;
// Defined as asynchronous transmission mode
Xmldoc = false;
// The XMLHttp class that needs to be created when the browser such as Safari is killed
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 ){}
}
}
}
// Return when 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 ','')
// Receives the complete Server Response
If (xmldoc. readyState = 1 ){
$ ("Loadifo"). innerHTML = "connect to server"
}
Else if (xmldoc. readyState = 2 ){
$ ("Loadifo"). innerHTML = "start to load data"
}
Else if (xmldoc. readyState = 3 ){
$ ("Loadifo"). innerHTML = "loading data"
Settime (loadtime)
}
Else if (xmldoc. readyState = 4 ){
// The HTTP server response value is successful.
If (xmldoc. status = 200 ){
// Write the string returned by the server to the area where the ID is showdiv in the page.
$ ("Loadifo"). innerHTML = "loaded"
Var response = xmldoc. responseText;
Settime (ifodis)
$ ("Prolist"). innerHTML = response;
}
Else {
$ ("Loadifo"). innerHTML = "error" + xmldoc. statusText + "Please reselect ";
}
}
}
</Script>

<Style type = "text/css">
<! --
Body {
Margin: 0px;
Padding: 0px;
Font-size: 9pt;
}
-->
</Style>
</Head>

<Body onload = "loadurl ('chxx0138 ')">
<Div>
<Select onchange = "loadurl (this. value)">
<Option value = "CHXX0138" selected = "selected"> Wuhan </option>
<Option value = "CHXX0097"> Nanchang </option>
<Option value = "CHXX0502"> Haikou </option>
<Option value = "CHXX0008"> Beijing </option>
<Option value = "CHXX0116"> Shanghai </option>
<Option value = "CHXX0037"> Guangzhou </option>
<Option value = "CHXX0259"> Yinchuan </option>
<Option value = "CHXX0165"> Zhengzhou </option>
<Option value = "CHXX0013"> Changsha </option>
<Option value = "CHXX0390"> Hangzhou </option>
<Option value = "CHXX0049"> Hong Kong </option>
<Option value = "CHXX0146"> Xi'an </option>
<Option value = "CHXX0016"> Chengdu </option>
<Option value = "CHXX0110"> Qingdao </option>
<Option value = "CHXX0039"> Guiyang </option>
<Option value = "CHXX0064"> Jinan </option>
<Option value = "CHXX0448"> Hefei </option>
<Option value = "CHXX0031"> Fuzhou </option>
<Option value = "CHXX0099"> Nanjing </option>
<Option value = "ITXX0042"> Milan </option>
</Select>
<Span id = "loadifo"> </span> </div>
<Div id = "prolist"> </div>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.