-2

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?

clinton3141
  • 4,751
  • 3
  • 33
  • 46
  • `data`'s empty probably – Andrew Li Sep 11 '16 at 20:28
  • no, it's not. url works finely when you just put it in browser – Max Harbarth Sep 11 '16 at 20:29
  • 4
    Did you miss the message: `XMLHttpRequest cannot load https://api.forecast.io/forecast/099d7717a79a457e72fd4b3e6e54c89c/55.9931803,92.773715?_=1473625797525. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://stackoverflow.com' is therefore not allowed access.` – epascarello Sep 11 '16 at 20:30
  • Try placing a `console.log('test')` to see if the code is actually executing. – yuriy636 Sep 11 '16 at 20:30

1 Answers1

2

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.