Reputation: 246
So right now I'm working on the FCC local weather app and I'm having some difficulty retrieving data from the weather API I'm using. I decided to use the Dark Sky API over the suggested Open Weather API just to change things up. This is what I have so far:
$(document).ready(function() {
var lat, lon, city, api, temp, sum, windSpeed, percip;
var apiKey = "##########################";
$.getJSON("http://ip-api.com/json", function(data1) {
lat = data1.lat;
lon = data1.lon;
city = data1.city;
api = 'https://api.forecast.io/forecast/' + apiKey + '/' + lat + ',' + lon + '';
$.getJSON(api, function(data2) {
temp = data2.currently.temperature;
sum = data2.currently.summary;
windSpeed = data2.currently.windSpeed;
percip = data2.currently.precipProbability;
console.log(temp);
});
});
});
So right now I can get the ip-api to output to the console any of the variables that are assigned within that call. My issue is that I can't get the second call to the Dark Sky API to output anything to the console when I try to check for any of the variables value. That being said, the concatenated api variable will return the JSON data I need, but the method cant seem to retrieve it.
I tried to get some help on the FCC gitter chat and someone suggested not to mix http and https protocols, but switching both to the same protocol be it http or https wont return data at all.
I hope this is enough information.
Upvotes: 1
Views: 1614
Reputation: 681
What you are missing is the callback
query.
In the api
variable definition, add ?callback=?
Try the following.
api = 'https://api.forecast.io/forecast/' + apiKey + '/' + lat + ',' + lon + '?callback=?';
TEST
Here is a test in JSFiddle:
https://jsfiddle.net/Esko/hqnszd5t/
Upvotes: 1