這篇文章主要講解了“如何編寫asp配合AJAX天氣預(yù)報(bào)的webService”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“如何編寫asp配合AJAX天氣預(yù)報(bào)的webService”吧!
創(chuàng)新互聯(lián)自2013年起,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元東方做網(wǎng)站,已為上家服務(wù),為東方各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
代碼如下:
<%@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")
//轉(zhuǎn)換英文為中文
var cityCH=EN2CH(cityV)
function EN2CH(obj){
if(obj=="Wuhan"){return "武漢"}
else if(obj=="Nanchang"){return "南昌"}
else if(obj=="Haikou"){return "???quot;}
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 "長(zhǎng)沙"}
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 "貴陽(yáng)"}
else if(obj=="Jinan"){return "濟(jì)南"}
else if(obj=="Hefei"){return "合肥"}
else if(obj=="Fuzhou"){return "福州"}
else if(obj=="Nanjing"){return "南京"}
else{return obj}
}
//風(fēng)向函數(shù)
var windCH=wind(directionV)
function wind(a){
if(a>337 && a<=360){return "北風(fēng)"};
else if(a>=0 && a<=22){return "北風(fēng)"};
else if(a>22 && a<=67){return "東北風(fēng)"};
else if(a>67 && a<=112){return "東風(fēng)"};
else if(a>112 && a<=157){return "東南風(fēng)"};
else if(a>157 && a<=202){return "南風(fēng)"};
else if(a>202 && a<=247){return "西南風(fēng)"};
else if(a>247 && a<=292){return "西風(fēng)"};
else if(a>292 && a<=337){return "西北風(fēng)"};
}
//能見(jiàn)度函數(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 "<img src=\"http\://us\.i1\.yimg\.com/us\.yimg.com/i/us/we/52/"+obj+"\.gif\" />"
}
//星期替換
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}
}
%>
<table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="6" align="center"><%=cityCH%><br />
<%=weaNum%><br />
<%=textCH%></td>
<td align="right">感覺(jué):</td>
<td align="center"><%=chillV%>°</td>
</tr>
<tr >
<td align="right">實(shí)際:</td>
<td align="center"><%=tempV%>°</td>
</tr>
<tr>
<td align="right">風(fēng)向:</td>
<td align="center"><%=windCH%></td>
</tr>
<tr >
<td align="right">風(fēng)速:</td>
<td align="center"><%=speedV%>Kph</td>
</tr>
<tr>
<td align="right">濕度:</td>
<td align="center"><%=humidityV%>%</td>
</tr>
<tr >
<td align="right">能見(jiàn)度:</td>
<td align="center"><%=visibility%>km</td>
</tr>
</table>
<table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center" class="time"><%=lastV%></td>
</tr>
<tr>
<td bgcolor="#FFFFCC">日出:<%=sunriseV%></td>
<td bgcolor="#FFCC00">日落:<%=sunsetV%></td>
</tr>
</table>
<table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<%
for(var i=0; i<2; i++){
var dayV=attri(forecastNode,i,"day")
var dateV=attri(forecastNode,i,"date")
var lowV=attri(forecastNode,i,"low")
var highV=attri(forecastNode,i,"high")
var texttV=attri(forecastNode,i,"text")
var codetV=attri(forecastNode,i,"code")
var dayCH=dayEn(dayV)
var texttCH=tEN2CH(texttV)
var weabmp=weaimg(codetV)
//var weatNum=weaimg(codetV)
%>
<td align="center"><%=dayCH%><br /><%=weabmp%><br /><%=texttCH%><br />最高<%=highV%>°<br />最低<%=lowV%>°</td>
<%
}
%>
</tr>
</table>
感謝各位的閱讀,以上就是“如何編寫asp配合AJAX天氣預(yù)報(bào)的webService”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)如何編寫asp配合AJAX天氣預(yù)報(bào)的webService這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
分享文章:如何編寫asp配合AJAX天氣預(yù)報(bào)的webService
分享路徑:http://aaarwkj.com/article2/pccdic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、自適應(yīng)網(wǎng)站、Google、外貿(mào)建站、定制網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)