Ajax weather forecast foreground _ajax related

Source: Internet
Author: User
Directly with the previous background program, you can achieve cross-domain crawling weather information.
Firefox is now perfectly supported.
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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 (a) {
SetTimeout (a,1000);
}
function Loadtime () {
$ ("Loadifo"). InnerHTML + = "."
}
XML Data Binding
var xmldoc = false;
function Loadurl (n) {
Generate random numbers, while limiting refresh times
var now=new Date ();
var num=now.valueof ();
Defining Address Parameters
url = "weather.asp?n=" +n+ "&id=" +num;
Defined as asynchronous transfer mode
XmlDoc = false;
XMLHTTP classes that need to be created when 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) {}
}
}
}
Cannot create XMLHTTP class when it returns
if (! xmldoc) {
return false;
}
Calling the CheckState function
Xmldoc.onreadystatechange = CheckState;
Xmldoc.open (' Get ', url,true);
Xmldoc.send (NULL);
}
State detection
function CheckState () {
Btnsty (' Loadifo ', ')
Receive Full server response
if (xmldoc.readystate = = 1) {
$ ("Loadifo"). InnerHTML = "Connect to Server"
}
else if (xmldoc.readystate = 2) {
$ ("Loadifo"). InnerHTML = "Start Loading Data"
}
else if (xmldoc.readystate = 3) {
$ ("Loadifo"). InnerHTML = "Loading Data"
SetTime (Loadtime)
}
else if (xmldoc.readystate = 4) {
HTTP Server Response value succeeded
if (Xmldoc.status = = 200) {
Writes the string returned by the server to the page with an ID showdiv area
$ ("Loadifo"). InnerHTML = "Load Complete"
var response = Xmldoc.responsetext;
SetTime (Ifodis)
$ ("Prolist"). InnerHTML = response;
}
else{
$ ("Loadifo"). InnerHTML = "error" +xmldoc.statustext+ "please choose Again";
}
}
}
</script>

<style type= "Text/css" >
<!--
Body {
margin:0px;
padding:0px;
font-size:9pt;
}
-->
</style>

<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>

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.