因為發現AJAX目前跨域有點問題,只能在IE里面設置才可以使用,所以自己就寫了個簡單ASP的webService,其實作用就是一個小偷程序,把雅虎的天氣抓了過來,然后生成XML。先從這里開始吧,以后會考慮添加數據庫,這樣客戶端寫好后讀取速度就很快了。
習慣了用JS寫東西,一不小心ASP也全拿JS寫的,呵呵,有時間再改成VB。
我再鄙視他一下,FLASH是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=c&id="+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 "銀川"}