這篇文章主要講解了“如何編寫asp配合AJAX天氣預(yù)報的webService”,文中的講解內(nèi)容簡單清晰,易于學(xué)習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習“如何編寫asp配合AJAX天氣預(yù)報的webService”吧!
10余年的永昌網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。全網(wǎng)整合營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整永昌建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“永昌網(wǎng)站設(shè)計”,“永昌網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。代碼如下:
<%@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")
//轉(zhuǎn)換英文為中文
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
}
//轉(zhuǎn)換天氣為中文
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 "晴轉(zhuǎn)云"}
else if(obj=="AM Clouds/PM Sun/Wind"){return "云轉(zhuǎn)晴"}
else if(obj=="AM Showers"){return "晨雨"}
else{return obj}
}
//天氣圖片
var weaNum=weaimg(codeV)
function weaimg(obj){
return ""
}
//星期替換
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}
}
%>
<%=cityCH%> <%=weaNum%> <%=textCH%> | 感覺: | <%=chillV%>° |
實際: | <%=tempV%>° | |
風向: | <%=windCH%> | |
風速: | <%=speedV%>Kph | |
濕度: | <%=humidityV%>% | |
能見度: | <%=visibility%>km |
<%=lastV%> | |
日出:<%=sunriseV%> | 日落:<%=sunsetV%> |
<%=dayCH%> <%=weabmp%> <%=texttCH%> 高<%=highV%>° 最低<%=lowV%>° |
感謝各位的閱讀,以上就是“如何編寫asp配合AJAX天氣預(yù)報的webService”的內(nèi)容了,經(jīng)過本文的學(xué)習后,相信大家對如何編寫asp配合AJAX天氣預(yù)報的webService這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!