Asp for webService with AJAX Weather Forecast

Source: Internet
Author: User

I found that AJAX currently has a problem with cross-origin. It can only be set in IE. So I wrote a simple ASP webService, which is actually a thief program, capture Yahoo's weather and generate XML. Let's start from here. In the future, we will consider adding a database so that the client can read the database quickly after writing it.

I am used to writing things with JS. I accidentally wrote ASP all using JS. Haha, I have time to change it to VB.
I despise him again. FLASH was launched N years ago. Although it took a long time to lose it, the help of AW will gradually improve.

The fire finally subsided, and it was another thing that was quietly changed.
Copy codeThe Code is as follows:
<% @ 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.doc umentElement;
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 ast1_mynode = response. selectNodes ("// rss/channel/yweather: ast1_my ");
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 attributes
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 (ast1_mynode, 0, "sunrise ")
Var sunsetV = attri (ast1_mynode, 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 (){
If (a> 337 & a <= 360) {return "North Wind "};
Else if (a >=0 & a <= 22) {return "northwind "};
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 "Nanfeng "};
Else if (a> 202 & a <= 247) {return "SouthWest Wind "};
Else if (a> 247 & a <= 292) {return ""};
Else if (a> 292 & a <= 337) {return "northwest wind "};
}
// Visibility Function
Visibility = vis (visibilityV)
Function vis (){
Returns a/100
}
// Convert the weather to Chinese
Var textCH = tEN2CH (textV)
Function tEN2CH (obj ){
If (obj = "Clear") {return "Clear "}
Else if (obj = "Sunny") {return "Sunny "}
Else if (obj = "Partly Cloudy") {return "partial cloud "}
Else if (obj = "Mostly Clear") {return "Clear "}
Else if (obj = "Mostly Sunny") {return "Xiaoyun "}
Else if (obj = "Mostly Cloudy") {return "Multi-cloud "}
Else if (obj = "Cloudy") {return "Cloud "}
Else if (obj = "Sunny/Wind") {return "Clear cloud "}
Else if (obj = "AM Clouds/PM Sun/Wind") {return ""}
Else if (obj = "AM Showers") {return "morning rain "}
Else {return obj}
}
// Weather Image
Var weaNum = weaimg (codeV)
Function weaimg (obj ){
Return "}
// Day of the week
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">
<Tr>
<Td rowspan = "6" align = "center"> <% = cityCH %> <br/>
<% = WeaNum %> <br/>
<% = TextCH %> </td>
<Td align = "right"> feeling: </td>
<Td align = "center"> <% = chillV %> ° </td>
</Tr>
<Tr style = "background-color: # E6F5FF">
<Td align = "right"> actual: </td>
<Td align = "center"> <% = tempV %> ° </td>
</Tr>
<Tr>
<Td align = "right"> wind direction: </td>
<Td align = "center"> <% = windCH %> </td>
</Tr>
<Tr style = "background-color: # E6F5FF">
<Td align = "right"> wind speed: </td>
<Td align = "center"> <% = speedV %> Kph </td>
</Tr>
<Tr>
<Td align = "right"> humidity: </td>
<Td align = "center"> <% = humidityV %> % </td>
</Tr>
<Tr style = "background-color: # E6F5FF">
<Td align = "right"> visibility: </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"> sunrise: <% = sunriseV %> </td>
<Td bgcolor = "# FFCC00"> sunset: <% = 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/> maximum <% = highV %> ° <br/> Minimum <% = lowV %> ° </td>
<%
}
%>
</Tr>
</Table>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.