I'm trying to get the Yahoo Weather with JavaScript. I originally made a proxy, but found that clumsy.
So can get the JSON response from http://weather.yahooapis.com/forecastjson?w=9807, and I know that the script tag can avoid the same-domain restrictions, but I'm getting a syntax error.
Yahoo's JSON response isn't padded; I've got the callback working but the browser isn't interpreting the JSON properly.
I've seen many examples like How to read yahoo weather JSON data with Jquery ajax but it's so weird because all those give me the cross-domain error.
Can anyone help me with this? Cross domain, yahoo weather, without special servers or YQL or anything like that. Something that just works out of the box.
If you're expecting JSON-P
then you need to add a callback function name to the query. With jQuery, this is always ?
. jQuery will substitute it with a randomly generated function name:
var query = escape('select item from weather.forecast where location="CAXX0518"'),
url = "http://query.yahooapis.com/v1/public/yql?q=" + query + "&format=json&callback=?";
$.getJSON(url, function(data) {
console.log( data );
});