网学网为广大网友收集整理了,配合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
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("//rss/channel/lastBuildDate");
var cityNode=response.selectNodes("//rss/channel/yweather:location");
var windNode=response.selectNodes("//rss/channel/yweather:wind");
var atmosphereNode=response.selectNodes("//rss/channel/yweather:atmosphere");
var astronomyNode=response.selectNodes("//rss/channel/yweather:astronomy");
var conditionNode=response.selectNodes("//rss/channel/item/yweather:condition");
var forecastNode=response.selectNodes("//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