Max Harbarth Max Harbarth - 2 months ago 19
Javascript Question

Empty console after console.log() call in Javascript

So, my code is

$.getJSON("https://api.forecast.io/forecast/API_KEY/55.9931803,92.773715", function(data){
console.log(data);
})


but console is empty. No errors, just nothing. what am I doing wrong?

Answer

Won't work the way that you're expecting it to (unless you're running that javascript from a frontend view that is hosted at forecast.io).

You are running into the classic Cross Domain resource issue. https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Looks like they don't have Access-Control-Allow-Origin: *

You'll probably need to curl the request on your web server (server-side) and issue your javascript request to your own web server.

Comments