配合AJAX天气预报的webService 之asp

你静候着秋天的温柔,留我在风景之外。把眼睛留给风光,把体重留给美食。我坐在椅子上,看日出复活;我坐在夕阳里,看城市的衰落。
因为发现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"<imgsrc=\"http\://us\.i1\.yimg\.com/us\.yimg.com/i/us/we/52/"+obj+"\.gif\"/>"
}
//星期替换
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}
}
%>
<tablewidth="163"border="0"align="center"cellpadding="0"cellspacing="0">
<tr>
<tdrowspan="6"align="center"><%=cityCH%><br/>
<%=weaNum%><br/>
<%=textCH%></td>
<tdalign="right">感觉:</td>
<tdalign="center"><%=chillV%>°</td>
</tr>
<trstyle="background-color:#E6F5FF">
<tdalign="right">实际:</td>
<tdalign="center"><%=tempV%>°</td>
</tr>
<tr>
<tdalign="right">风向:</td>
<tdalign="center"><%=windCH%></td>
</tr>
<trstyle="background-color:#E6F5FF">
<tdalign="right">风速:</td>
<tdalign="center"><%=speedV%>Kph</td>
</tr>
<tr>
<tdalign="right">湿度:</td>
<tdalign="center"><%=humidityV%>%</td>
</tr>
<trstyle="background-color:#E6F5FF">
<tdalign="right">能见度:</td>
<tdalign="center"><%=visibility%>km</td>
</tr>
</table>
<tablewidth="163"border="0"align="center"cellpadding="0"cellspacing="0">
<tr>
<tdcolspan="2"align="center"class="time"><%=lastV%></td>
</tr>
<tr>
<tdbgcolor="#FFFFCC">日出:<%=sunriseV%></td>
<tdbgcolor="#FFCC00">日落:<%=sunsetV%></td>
</tr>
</table>
<tablewidth="163"border="0"align="center"cellpadding="0"cellspacing="0">
<tr>
<%
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)
%>
<tdalign="center"><%=dayCH%><br/><%=weabmp%><br/><%=texttCH%><br/>最高<%=highV%>°<br/>最低<%=lowV%>°</td>
<%
}
%>
</tr>
</table>

到此这篇关于配合AJAX天气预报的webService 之asp就介绍到这了。是年夜山就有高度和坡度,是江河就有宽度和深度,是人就存在不足和毛病。更多相关配合AJAX天气预报的webService 之asp内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
实现AJAX异步调用和局部刷新的基本步骤

Ajax实现上传图像功能的示例详解

Ajax校验用户名是否存在的方法

AJAX请求数据及实现跨域的三种方法详解

ajax接口文档url路径的简写实例