欢迎来到福编程网,本站提供各种互联网专业知识!

配合AJAX天气预报的webService 之asp

发布时间:2007-01-31 作者: 来源:转载
因为发现AJAX目前跨域有点问题,只能在IE里面设置才可以使用,所以自己就写了个简单ASP的webService,其实作用就是一个小偷程序,把雅虎的天气抓了过来,然后生成XML。先从这里开始吧,以后会考虑添加数据库,这样客户端写好后读取速度就很快了。习惯了用JS写
因为发现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
varN=Request("n")
varNum=Request("id")
varurl="http://xml.weather.yahoo.com/forecastrss?p="+N+"&u=c&id="+Num;
varxmldoc=Server.CreateObject("Microsoft.Xmlhttp");
xmldoc.open('GET',url,false);
xmldoc.send(null);
varresponse=xmldoc.responseXML.documentElement;
varlastNode=response.selectNodes("//rss/channel/lastBuildDate");
varcityNode=response.selectNodes("//rss/channel/yweather:location");
varwindNode=response.selectNodes("//rss/channel/yweather:wind");
varatmosphereNode=response.selectNodes("//rss/channel/yweather:atmosphere");
varastronomyNode=response.selectNodes("//rss/channel/yweather:astronomy");
varconditionNode=response.selectNodes("//rss/channel/item/yweather:condition");
varforecastNode=response.selectNodes("//rss/channel/item/yweather:forecast");
varlastV=lastNode(0).firstChild.nodeValue
//编辑属性
functionattri(a,b,c){
returna(b).attributes.getNamedItem(c).value
}
varcityV=attri(cityNode,0,"city")
varchillV=attri(windNode,0,"chill")
vardirectionV=attri(windNode,0,"direction")
varspeedV=attri(windNode,0,"speed")
varhumidityV=attri(atmosphereNode,0,"humidity")
varvisibilityV=attri(atmosphereNode,0,"visibility")
varsunriseV=attri(astronomyNode,0,"sunrise")
varsunsetV=attri(astronomyNode,0,"sunset")
vartextV=attri(conditionNode,0,"text")
varcodeV=attri(conditionNode,0,"code")
vartempV=attri(conditionNode,0,"temp")
//转换英文为中文
varcityCH=EN2CH(cityV)
functionEN2CH(obj){
if(obj=="Wuhan"){return"武汉"}
elseif(obj=="Nanchang"){return"南昌"}
elseif(obj=="Haikou"){return"海口"}
elseif(obj=="Beijing"){return"北京"}
elseif(obj=="Shanghai"){return"上海"}
elseif(obj=="Guangzhou"){return"广州"}
elseif(obj=="Yinchuan"){return"银川"}
elseif(obj=="Zhengzhou"){return"郑州"}
elseif(obj=="Changsha"){return"长沙"}
elseif(obj=="Hanzhong"){return"杭州"}
elseif(obj=="HongKong"){return"香港"}
elseif(obj=="Xin'an"){return"西安"}
elseif(obj=="Chengdu"){return"成都"}
elseif(obj=="Qingdao"){return"青岛"}
elseif(obj=="Guiyang"){return"贵阳"}
elseif(obj=="Jinan"){return"济南"}
elseif(obj=="Hefei"){return"合肥"}
elseif(obj=="Fuzhou"){return"福州"}
elseif(obj=="Nanjing"){return"南京"}
else{returnobj}
}
//风向函数
varwindCH=wind(directionV)
functionwind(a){
if(a>337&&a<=360){return"北风"};
elseif(a>=0&&a<=22){return"北风"};
elseif(a>22&&a<=67){return"东北风"};
elseif(a>67&&a<=112){return"东风"};
elseif(a>112&&a<=157){return"东南风"};
elseif(a>157&&a<=202){return"南风"};
elseif(a>202&&a<=247){return"西南风"};
elseif(a>247&&a<=292){return"西风"};
elseif(a>292&&a<=337){return"西北风"};
}
//能见度函数
visibility=vis(visibilityV)
functionvis(a){
returna/100
}
//转换天气为中文
vartextCH=tEN2CH(textV)
functiontEN2CH(obj){
if(obj=="Clear"){return"晴朗"}
elseif(obj=="Sunny"){return"晴天"}
elseif(obj=="PartlyCloudy"){return"局部有云"}
elseif(obj=="MostlyClear"){return"晴"}
elseif(obj=="MostlySunny"){return"小云"}
elseif(obj=="MostlyCloudy"){return"多云"}
elseif(obj=="Cloudy"){return"云"}
elseif(obj=="Sunny/Wind"){return"晴转云"}
elseif(obj=="AMClouds/PMSun/Wind"){return"云转晴"}
elseif(obj=="AMShowers"){return"晨雨"}
else{returnobj}
}
//天气图片
varweaNum=weaimg(codeV)
functionweaimg(obj){
return""
}
//星期替换
functiondayEn(obj){
if(obj=="Sun"){return"星期日"}
elseif(obj=="Mon"){return"星期一"}
elseif(obj=="Tue"){return"星期二"}
elseif(obj=="Wed"){return"星期三"}
elseif(obj=="Thu"){return"星期四"}
elseif(obj=="Fri"){return"星期五"}
elseif(obj=="Sat"){return"星期六"}
else{returnobj}
}
%>


<%=cityCH%>


<%=weaNum%>


<%=textCH%>
感觉:
<%=chillV%>°


实际:
<%=tempV%>°


风向:
<%=windCH%>


风速:
<%=speedV%>Kph


湿度:
<%=humidityV%>%


能见度:
<%=visibility%>km




<%=lastV%>


日出:<%=sunriseV%>
日落:<%=sunsetV%>




<%
for(vari=0;i<2;i++){
vardayV=attri(forecastNode,i,"day")
vardateV=attri(forecastNode,i,"date")
varlowV=attri(forecastNode,i,"low")
varhighV=attri(forecastNode,i,"high")
vartexttV=attri(forecastNode,i,"text")
varcodetV=attri(forecastNode,i,"code")
vardayCH=dayEn(dayV)
vartexttCH=tEN2CH(texttV)
varweabmp=weaimg(codetV)
//varweatNum=weaimg(codetV)
%>
<%=dayCH%>

<%=weabmp%>

<%=texttCH%>

最高<%=highV%>°

最低<%=lowV%>°
<%
}
%>

相关推荐