How can I access the following data? At the moment I only want to play around with data so that I can better understand how it all works. I have never worked with APIs before, however I am familiar with the concept of JSON.
$.getJSON( "https://api.forecast.io/forecast/APIKEY/40.463487,17.248535", function( data ) {
console.log('here');
console.log(data);
});
I have tried this on my local and it returns: XMLHttpRequest cannot load https://api.forecast.io/forecast/APIKEY/40.463487,17.248535. Origin http://weathercast.com is not allowed by Access-Control-Allow-Origin.
All I need is the data.
you can't do cross-domain AJAX query,
if you want to resolve this, you can use JSONP:
$.ajax({
url: "https://api.forecast.io/forecast/APIKEY/40.463487,17.248535",
dataType: "jsonp",
success: function (data) {
console.log('here');
console.log(data);
}
});
The reason this isn't working is because of the cross-domain security policy that your browser has. You cannot issue JSON requests to other domains.
But! JSONP to the rescue! Does Forecast.io have a JSONP endpoint? If so, you're in luck. If not, you will need to implement a server-side proxy for the requests to another domain, and call that proxy from within your javascript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With