I can't request data by YQuery!!
I want to create weather in my website, but i have a problem, when i select any city, i can't receive data. Can you help me? thanks you very much!
Code i write here:
"<script type="text/javascript">
function showWeatherCallback(data) {
var channel = data.query.results.weather.rss.channel,
img = channel.item.description.match(/http:\/\/[^"']*/),
html = '<strong>City : </strong> ' + channel.location.city + '<br />' +
'<img style="vertical-align:bottom" height="52" width="52" src="' + img + '" /> '+
'<strong>Do am:</strong> ' + channel.atmosphere.humidity + '%<br />' +
'<strong>Nhiet do thap:</strong> ' + channel.item.forecast[0].low+ '°' +channel.units.temperature +'<br />' +
'<strong>Nhiet do cao:</strong> ' + channel.item.forecast[0].high+ '°' +channel.units.temperature +'<br />' +
'<strong>Nhiet do thap ngay mai:</strong> ' + channel.item.forecast[1].low+ '°' +channel.units.temperature +'<br />' +
'<strong>Nhiet do cao ngay mai:</strong> ' + channel.item.forecast[1].high+ '°' +channel.units.temperature +'<br />' +
'<strong>Suc gio:</strong> ' + channel.wind.speed + ' km/h <br />';
document.write(html);
}
/**
* Show weather information. Use YQL to get information
* location: in format "city, country"
*
* Ex: showWeather('hanoi,vietnam');
*/
function showWeather(location,tempType) {
var baseUrl = 'http://query.yahooapis.com/v1/public/yql?q=',
q = 'use "http://github.com/yql/yql-tables/raw/master/weather/weather.bylocation.xml" as we;' +
'select * from we where location="' + location + '" and unit="'+ tempType +'"',
url = baseUrl + encodeURIComponent(q) + '&format=json&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=showWeatherCallback';
//document.write('<script type="text/javascript" src="' + url + '"></' + 'script>');
}
</script>
<div>
<form method="post">
<select onchange="showWeather('this.value','c');">
<option selected="selected" value="hanoi, vietnam">Ha Noi</option>
<option value="nhatrang, vietnam">Nha Trang</option>
<option value="pleaiku, vietnam">Pleiku</option>
<option value="hochiminh, vietnam">TP HCM</option>
</select>
<p id="img-Do"><img alt="" class="img-weather" src="/Images/Weather/i_nhieumay.gif"> <img alt="" class="img-weather" src="/Images/Weather/2.gif"><img alt="" class="img-weather" src="/Images/Weather/0.gif"><img alt="" class="img-weather" src="/Images/Weather/c.gif"></p>
<p id="txt-Weather"><b>Nhieu may</b><br>do am 84%<br>Gio dong bac<br>toc do m/s</p>
<script language="javascript" type="text/javascript">test();</script>
</form>
</div>"
by
0 Replies