Why isn't getJSON getting a response?

I am unable to get a response from getJSON from OpenWeatherMap for the weather app project.

The strange thing is that the actual API call to OpenWeatherMap does return a valid JSON object.

So, I wanted to output a debug string to the console to confirm getJSON is running but nothing outputs there as well.

What am I missing?

var apiCall = "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&units=imperial&APPID=" + myAPIKey;
// I've taken this api call and pasted it into a webpage and it returns a valid JSON object
$.getJSON(apiCall, function(json){
// Wanted to output a debug string to the console.  But "test" never outputs to the console.


could you post a link to your full code please


Your immediate issue is a cross domain issue. ie, geo location requires https in some (and soon all) browsers. But because your api is http, it hangs as a security issue.

The solution is to ditch geo (not an option for me, personally, cos it’s cool) or use a different API. dark skies and Apixu amongst others support this feature for free. Open-weather makes you pay to use https.

you can also use crossorigin.me for a quicker fix but imo the performance hit makes it untenable.

In short, choose a different api service if you want to use geo.

I haven’t checked for other errors.



Thanks mark. That was indeed the problem. Will try out both the crossorign.me solution as well as using a different weather api service (which is odd since OpenWeatherMap was the api service that the FreeCodeCamp project guide recommended).

1 Like