使用 ajax 或 jquery 查询 msn 天气 api 的示例

发布于 2024-09-25 15:00:45 字数 282 浏览 1 评论 0原文

我无法找到一个简单的示例来演示如何使用 ajax 或 jquery 查询 msn 或 yahoo 天气 api。

我想了解如何将查询传递给这些 api,然后检索字符串信息,然后在 html 页面上将其呈现给用户。

我已经在互联网上搜索了两天,但仍然没有找到关于如何查询 api 然后检索数据的简单示例。

我想了解这一点的原因是我正在构建一个 Windows 侧边栏小工具,因此任何有关此主题的信息都将非常感激。

如果您知道 Windows 天气侧边栏小工具的工作原理,请提供链接和信息。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断桥再见 2024-10-02 15:00:45

如果您使用 YQL 并请求 JSON,请参阅以下示例 URL:

http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2248907 %22&format=json

然后您可以使用 jQuery 获取该 JSON,然后使用返回的描述或使用其他一些数据来生成您想要的内容。

在 Firebug 控制台窗口中尝试以下操作:

$.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 );
    }
} );

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 );
    }
} );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文