因為發(fā)現(xiàn)AJAX目前跨域有點問題,只能在IE里面設置才可以使用,所以自己就寫了個簡單ASP的webService,其實作用就是一個小偷程序,把雅虎的天氣抓了過來,然后生成XML。先從這里開始吧,以后會考慮添加數(shù)據(jù)庫,這樣客戶端寫好后讀取速度就很快了。
習慣了用JS寫東西,一不小心ASP也全拿JS寫的,呵呵,有時間再改成VB。
我再鄙視他一下,F(xiàn)LASH是N年前就搞過的,時間雖然丟的有點長了,但是在AW的幫助,慢慢就會有所起色。
總算平息了火,還算是又默默改變了一件事情。
復制代碼 代碼如下:
%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
%
Session.CodePage = "65001"
Response.contentType="text/html"
Response.Expires = 0
var N=Request("n")
var Num=Request("id")
var url="http://xml.weather.yahoo.com/forecastrss?p="+N+"u=cid="+Num;
var xmldoc=Server.CreateObject("Microsoft.Xmlhttp");
xmldoc.open('GET',url,false);
xmldoc.send(null);
var response = xmldoc.responseXML.documentElement;
var lastNode=response.selectNodes("http://rss/channel/lastBuildDate");
var cityNode=response.selectNodes("http://rss/channel/yweather:location");
var windNode=response.selectNodes("http://rss/channel/yweather:wind");
var atmosphereNode=response.selectNodes("http://rss/channel/yweather:atmosphere");
var astronomyNode=response.selectNodes("http://rss/channel/yweather:astronomy");
var conditionNode=response.selectNodes("http://rss/channel/item/yweather:condition");
var forecastNode=response.selectNodes("http://rss/channel/item/yweather:forecast");
var lastV=lastNode(0).firstChild.nodeValue
//編輯屬性
function attri(a,b,c){
return a(b).attributes.getNamedItem(c).value
}
var cityV=attri(cityNode,0,"city")
var chillV=attri(windNode,0,"chill")
var directionV=attri(windNode,0,"direction")
var speedV=attri(windNode,0,"speed")
var humidityV=attri(atmosphereNode,0,"humidity")
var visibilityV=attri(atmosphereNode,0,"visibility")
var sunriseV=attri(astronomyNode,0,"sunrise")
var sunsetV=attri(astronomyNode,0,"sunset")
var textV=attri(conditionNode,0,"text")
var codeV=attri(conditionNode,0,"code")
var tempV=attri(conditionNode,0,"temp")
//轉換英文為中文
var cityCH=EN2CH(cityV)
function EN2CH(obj){
if(obj=="Wuhan"){return "武漢"}
else if(obj=="Nanchang"){return "南昌"}
else if(obj=="Haikou"){return "海口"}
else if(obj=="Beijing"){return "北京"}
else if(obj=="Shanghai"){return "上海"}
else if(obj=="Guangzhou"){return "廣州"}
else if(obj=="Yinchuan"){return "銀川"}
else if(obj=="Zhengzhou"){return "鄭州"}
else if(obj=="Changsha"){return "長沙"}
else if(obj=="Hanzhong"){return "杭州"}
else if(obj=="Hong Kong"){return "香港"}
else if(obj=="Xin'an"){return "西安"}
else if(obj=="Chengdu"){return "成都"}
else if(obj=="Qingdao"){return "青島"}
else if(obj=="Guiyang"){return "貴陽"}
else if(obj=="Jinan"){return "濟南"}
else if(obj=="Hefei"){return "合肥"}
else if(obj=="Fuzhou"){return "福州"}
else if(obj=="Nanjing"){return "南京"}
else{return obj}
}
//風向函數(shù)
var windCH=wind(directionV)
function wind(a){
if(a>337 a=360){return "北風"};
else if(a>=0 a=22){return "北風"};
else if(a>22 a=67){return "東北風"};
else if(a>67 a=112){return "東風"};
else if(a>112 a=157){return "東南風"};
else if(a>157 a=202){return "南風"};
else if(a>202 a=247){return "西南風"};
else if(a>247 a=292){return "西風"};
else if(a>292 a=337){return "西北風"};
}
//能見度函數(shù)
visibility=vis(visibilityV)
function vis(a){
return a/100
}
//轉換天氣為中文
var textCH=tEN2CH(textV)
function tEN2CH(obj){
if(obj=="Clear"){return "晴朗"}
else if(obj=="Sunny"){return "晴天"}
else if(obj=="Partly Cloudy"){return "局部有云"}
else if(obj=="Mostly Clear"){return "晴"}
else if(obj=="Mostly Sunny"){return "小云"}
else if(obj=="Mostly Cloudy"){return "多云"}
else if(obj=="Cloudy"){return "云"}
else if(obj=="Sunny/Wind"){return "晴轉云"}
else if(obj=="AM Clouds/PM Sun/Wind"){return "云轉晴"}
else if(obj=="AM Showers"){return "晨雨"}
else{return obj}
}
//天氣圖片
var weaNum=weaimg(codeV)
function weaimg(obj){
return "img src=\"http\://us\.i1\.yimg\.com/us\.yimg.com/i/us/we/52/"+obj+"\.gif\" />"
}
//星期替換
function dayEn(obj){
if(obj=="Sun"){return "星期日"}
else if(obj=="Mon"){return "星期一"}
else if(obj=="Tue"){return "星期二"}
else if(obj=="Wed"){return "星期三"}
else if(obj=="Thu"){return "星期四"}
else if(obj=="Fri"){return "星期五"}
else if(obj=="Sat"){return "星期六"}
else{return obj}
}
%>
table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
tr>
td rowspan="6" align="center">%=cityCH%>br />
%=weaNum%>br />
%=textCH%>/td>
td align="right">感覺:/td>
td align="center">%=chillV%>°/td>
/tr>
tr style="background-color:#E6F5FF">
td align="right">實際:/td>
td align="center">%=tempV%>°/td>
/tr>
tr>
td align="right">風向:/td>
td align="center">%=windCH%>/td>
/tr>
tr style="background-color:#E6F5FF">
td align="right">風速:/td>
td align="center">%=speedV%>Kph/td>
/tr>
tr>
td align="right">濕度:/td>
td align="center">%=humidityV%>%/td>
/tr>
tr style="background-color:#E6F5FF">
td align="right">能見度:/td>
td align="center">%=visibility%>km/td>
/tr>
/table>
table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
tr>
td colspan="2" align="center" class="time">%=lastV%>/td>
/tr>
tr>
td bgcolor="#FFFFCC">日出:%=sunriseV%>/td>
td bgcolor="#FFCC00">日落:%=sunsetV%>/td>
/tr>
/table>
table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
tr>
%
for(var i=0; i2; i++){
var dayV=attri(forecastNode,i,"day")
var dateV=attri(forecastNode,i,"date")
var lowV=attri(forecastNode,i,"low")
var highV=attri(forecastNode,i,"high")
var texttV=attri(forecastNode,i,"text")
var codetV=attri(forecastNode,i,"code")
var dayCH=dayEn(dayV)
var texttCH=tEN2CH(texttV)
var weabmp=weaimg(codetV)
//var weatNum=weaimg(codetV)
%>
td align="center">%=dayCH%>br />%=weabmp%>br />%=texttCH%>br />最高%=highV%>°br />最低%=lowV%>°/td>
%
}
%>
/tr>
/table>
您可能感興趣的文章:- Ajax 通過城市名獲取數(shù)據(jù)(全國天氣預報API)
- PHP Ajax JavaScript Json獲取天氣信息實現(xiàn)代碼
- PHP+AJAX無刷新實現(xiàn)返回天氣預報數(shù)據(jù)
- JS HTML5 音樂天氣播放器(Ajax獲取天氣信息)
- AJAX集天氣\IP\多國語言翻譯MP3(可同步LRC歌詞顯示)\萬年歷查詢通
- 天楓AJAX天氣預報系統(tǒng)V1.0
- AJAX天氣預報前臺
- ajax獲取用戶所在地天氣的方法