0

I am making a json request that is valid however i am unable to see the response in the log when using:

console.log(data);

the first request works however the second does not.

Thanks

James Rand
  • 57
  • 1
  • 10

1 Answers1

1

http://maps.googleapis.com supports CORS, but https://api.forecast.io does not. For forecast.io, you should use JSONP, easiest way to do that in jQuery is adding "?callback=?" to request URL:

$.getJSON('https://api.forecast.io/forecast/<API KEY>/' + lat + ',' + lon + "?callback=?", function(data1) {
            console.log(data1.currently.summary);
        });

However, you should avoid exposing your api key as stated in forecast.io api docs. Creating a reverse proxy to that service might be a good idea.

pfyod
  • 617
  • 5
  • 11
  • i have reset the api key now so this will no longer work on the existing fiddles thanks for your help – James Rand Apr 04 '13 at 11:12
  • @JamesRand it's not just about fiddles. If you use JSONP directly to forecast.io, you have to have the API key somewhere in your JS source; someone might take that API key and abuse it. If you have access to server side of you application (and if it has one), you should create a service, that would act as a proxy that adds API key to your forecast.io requests. – pfyod Apr 04 '13 at 11:20
  • 1
    ah okay this is only a personal project so it should be okay i guess i only needed to reset the api key to protect the account on forcast io – James Rand Apr 04 '13 at 11:22