Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use multiple URLs with $.getJSON

I have a few lines of code:

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

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) {

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/'];

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

Could anyone please help me out? Thanks.

like image 513
LT86 Avatar asked Nov 28 '22 21:11

LT86


1 Answers

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) {

});
like image 132
adeneo Avatar answered Dec 11 '22 00:12

adeneo