使用说明:
提交城市名参数即可: weather.asp?city=北京
以下是weather.asp源代码: |
附上AJAX查询天气预报的相关代码:
以下是weather.js代码: // JavaScript Document var xmlhttp=null; function createxmlhttp(){ try { xmlhttp=new ActiveXObject("Msxml2.xmlhttp") ; } catch(e) { try { xmlhttp=new ActiveXObject("Microsoft.xmlhttp") ; } catch(oc) { xmlhttp=null ; } } if ( !xmlhttp && typeof XMLHttpRequest != "undefined" ) { xmlhttp = new XMLHttpRequest(); } if (!xmlhttp) { //alert("您的浏览器不支AJAX!"); } } function ajaxPost(url,reid){ createxmlhttp(); //getMode xmlhttp.open("get",url,true); xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded"); xmlhttp.onreadystatechange= function () { checkState(reid); } ; xmlhttp.send(null); } function checkState(reid){ if (xmlhttp.readyState == 4){ document.getElementById(reid).innerHTML="正在加载天气信息..."; if(xmlhttp.status == 200){ var retext = xmlhttp.responseText; document.getElementById(reid).innerHTML=retext; } } else{ document.getElementById(reid).innerHTML="正在加载天气信息..."; } } |
以下是index.html代码: <!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=gb2312" /> <title>天气预报接口小偷程序 - 阿里西西WEB开发,国内最大的WEB开发资源网站</title> <script type="text/JavaScript"> <!-- function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location=’"+selObj.options[selObj.selectedIndex].value+"’"); if (restore) selObj.selectedIndex=0; } //--> </script> </head> <body> <a href="www.alixixi.com"><img src="http://www.alixixi.com/images/alistudio.gif" alt="阿里西西" width="182" height="49" border=0 longdesc="http://www.alixixi.com" /></a> <br /> <hr /> <span id="weather"></span> <p> <script src="weather.js" language="javascript"></script> </p> <form name="form1" id="form1"> <select name="menu1" > <option value="">请选择城市</option> <option value="北京">北京</option> <option value="上海">上海</option> <option value="南宁">南宁</option> </select> <div>天气预报小偷程序示例</div> </form> </body> </html> |
如果需要现成的示例程序,请点击以下链接在本站下载栏目下载:
http://www.alixixi.com/down/Search.asp?wd=%CC%EC%C6%F8%D4%A4%B1%A8%BD%D3%BF%DA