将多个URL与$ .getJSON一起使用 [英] Use multiple URLs with $.getJSON

查看:208
本文介绍了将多个URL与$ .getJSON一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几行代码:

var url = 'http://api.spitcast.com/api/spot/forecast/1/';
var url_wind = 'http://api.spitcast.com/api/county/wind/orange-county/';

$.getJSON(url, function (data) {

etc...

如何将这两个URL都放入$ .getJSON命令中?我以为会很简单:

How would I pull both of these URLs into my $.getJSON command? I thought it would be as simple as:

$.getJSON(url, url_wind, function (data) {

我还尝试过将这两个URL分配给相同的变量,例如:

I have also tried assigning these two URLs to the same variable as such:

var url = ['http://api.spitcast.com/api/spot/forecast/1/','http://api.spitcast.com/api/county/wind/orange-county/'];

不幸的是,我没有运气从第二个URL提取信息.

Unfortunately I'm having no luck pulling the info from the second URL.

有人可以帮我吗?谢谢.

Could anyone please help me out? Thanks.

推荐答案

您将需要两个调用,但是可以使用$.when将它们绑定到相同的done()处理程序:

You'll need two calls, but you can use $.when to tie them to the same done() handler :

var url = 'http://api.spitcast.com/api/spot/forecast/1/';
var url_wind = 'http://api.spitcast.com/api/county/wind/orange-county/';

$.when(
    $.getJSON(url),
    $.getJSON(url_wind)
).done(function(result1, result2) {

});

这篇关于将多个URL与$ .getJSON一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆