ASP of WebService with Ajax weather forecast


Because I found that Ajax has some problems in cross domain at present, it can only be set up in ie, so I wrote a simple ASP WebService, which is actually a thief program to catch the weather of Yahoo, and then generate XML. Let’s start here first. We will consider adding databases in the future, so that the reading speed of the client will be very fast after it is written.

I’m used to writing with JS. If I’m not careful, ASP also writes with JS. Hehe, I’ll change it to VB when I have time.
I despise him again. Flash was done n years ago. Although the time has been lost for a long time, it will slowly improve with the help of aw.

At last, the fire subsided, and it changed another thing silently.

Copy codeThe code is as follows:
Session.CodePage = “65001”
Response.Expires = 0
var N=Request(“n”)
var Num=Request(“id”)
var url=””+N+”&u=c&id=”+Num;
var xmldoc=Server.CreateObject(“Microsoft.Xmlhttp”);‘GET’,url,false);
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
//Edit properties
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”)
//Convert English to Chinese
var cityCH=EN2CH(cityV)
function EN2CH(obj){
If (obj== “Wuhan”) {return “Wuhan”}
Else if (obj== “Nanchang”) {return “Nanchang”}
Else if (obj== “Haikou”) {return “Haikou”}
Else if (obj== “Beijing”) {return “Beijing”}
Else if (obj== “Shanghai”) {return “Shanghai”}
Else if (obj== “Guangzhou”) {return “Guangzhou”}
Else if (obj== “Yinchuan”) {return “Yinchuan”}
Else if (obj== “Zhengzhou”) {return “Zhengzhou”}
Else if (obj== “Changsha”) {return “Changsha”}
Else if (obj== “Hanzhong”) {return “Hangzhou”}
Else if (obj== “Hong Kong”) {return “Hong Kong”}
Else if (obj== “Xin’an”) {return “Xi’an”}
Else if (obj== “Chengdu”) {return “Chengdu”}
Else if (obj== “Qingdao”) {return “Qingdao”}
Else if (obj== “Guiyang”) {return “Guiyang”}
Else if (obj== “Jinan”) {return “Jinan”}
Else if (obj== “Hefei”) {return “Hefei”}
Else if (obj== “Fuzhou”) {return “Fuzhou”}
Else if (obj== “Nanjing”) {return “Nanjing”}
    else{return obj}
//Wind direction function
var windCH=wind(directionV)
function wind(a){
If (a>337 & & A < =360) {return “north wind”};
Else if (a>=0 & & A < =22) {return “north wind”};
Else if (a>22 & & A < =67) {return “northeast wind”};
Else if (a>67 & & A < =112) {return “Dongfeng”};
Else if (a>112 & & A < =157) {return “southeast wind”};
Else if (a>157 & & A < =202) {return “south wind”};
Else if (a>202 & & A < =247) {return “southwest wind”};
Else if (a>247 & & A < =292) {return “westerly”};
Else if (a>292 & & A < =337) {return “northwest wind”};
//Visibility function
function vis(a){
    return a/100
//Convert weather to Chinese
var textCH=tEN2CH(textV)
function tEN2CH(obj){
If (obj== “clear”) {return “sunny”}
Else if (obj== “sunny”) {return “sunny”}
Else if (obj== “partially cloudy”) {return “partially cloudy”}
Else if (obj== “mustly clear”) {return “sunny”}
Else if (obj== “mustly sunny”) {return “Xiaoyun”}
Else if (obj== “mustly cloudy”) {return “cloudy”}
Else if (obj== “cloudy”) {return “cloud”}
Else if (obj== “sunny/wind”) {return “sunny to cloud”}
Else if (obj== “am clouds/pm sun/wind”) {return “the cloud turns sunny”}
Else if (obj== “am showers”) {return “morning rain”}
    else{return obj}
//Weather pictures
var weaNum=weaimg(codeV)
function weaimg(obj){
    return “<img src=\”http\://us\.i1\.yimg\.com/us\”+obj+”\.gif\” />”
//Week replacement
function dayEn(obj){
If (obj== “sun”) {return “Sunday”}
Else if (obj== “mon”) {return “Monday”}
Else if (obj== “Tue”) {return “Tuesday”}
Else if (obj== “wed”) {return “Wednesday”}
Else if (obj== “Thu”) {return “Thursday”}
Else if (obj== “fri”) {return “Friday”}
Else if (obj== “SAT”) {return “Saturday”}
    else{return obj}
<table width=”163″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
    <td rowspan=”6″ align=”center”><%=cityCH%><br />
      <%=weaNum%><br />
<td align= “right” > Feeling:</td>
    <td align=”center”><%=chillV%>°</td>
  <tr style=”background-color:#E6F5FF”>
<td align= “right” > actual:</td>
    <td align=”center”><%=tempV%>°</td>
<td align= “right” > wind direction:</td>
    <td align=”center”><%=windCH%></td>
  <tr style=”background-color:#E6F5FF”>
<td align= “right” > wind speed:</td>
    <td align=”center”><%=speedV%>Kph</td>
<td align= “right” > humidity:</td>
    <td align=”center”><%=humidityV%>%</td>
  <tr style=”background-color:#E6F5FF”>
<td align= “right” > visibility:</td>
    <td align=”center”><%=visibility%>km</td>
<table width=”163″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
    <td colspan=”2″ align=”center” class=”time”><%=lastV%></td>
<td bgcolor= “\ffffcc” > Sunrise: <%=sunrise%></td>
<td bgcolor= “\ffcc00” > sunset: <%=sunsetv%></td>
<table width=”163″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
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 / > <%=textch%> < br / > maximum <%=highv%> ° <br / > minimum <%=lowv%> °</td>