Examples of quering the msn weather api using ajax or jquery
I am having trouble finding a simple example that demonstrates how to query the msn or yahoo weather api using ajax or jquery.
I want to understand how I can pass a query to these api's开发者_如何学Go and then retrieve string information back which I can then present to the user on a html page.
I have been searching the internet for two days and still have not find a simple example on how to query an api and then retrieve data back.
The reason I want to understand this is I am in the process of building a windows sidebar gadget, so any information on this subject as well would be really appreciated.
If you know how the Windows weather sidebar gadget works, please provide links and information.
If you use YQL and request JSON see this example URL:
http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2248907%22&format=json
Then you could use jQuery to get that JSON and then use the description that comes back or use some of the other data to generate what you want.
Try this in a firebug console window:
$.get( 'http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2248907%22&format=json', function( data ) {
data = JSON.parse( data );
if ( data.query.count > 0 ) {
$( 'body' ).append( data.query.results.channel.item.description );
}
} );
精彩评论