Basic AJAX question involving OpenWeatherMapAPI

Basic AJAX question involving OpenWeatherMapAPI
0.0 0



I want to have both hourly and daily data for my WeatherApp so I need calls from:

and also

Can this be done in one single AJAX call? If so, how?



Hi @RadDog25

It’s sort of possible in one call, basically you need to make 2 API calls and wait for both of them to come back.

// jQuery example

var hourly = $.getJSON('hourly_url');
var daily = $.getJSON('daily_url');

$.when(hourly, daily).done(function(hourlyResponse, dailyResponse) {
  // Do something with both.

// ES6 Fetch promise example

var hourly = fetch('hourly_url').then(res => res.json());
var daily = fetch('daily_url').then(res => res.json());

Promise.all([hourly, daily]).then(function(resArray) {
  resArray[0] // hourly data
  resArray[1] // daily data

For further reading about each method, check out:

Hope this helps!


I don’t think you can do them in one call. But you can fire them in parallel with jQuery’s $.when()


ES6 Promise.all() worked great. Thanks guys.