Using the Yahoo Weather API with JSON and the script tag

前端 未结 3 1592
自闭症患者
自闭症患者 2021-01-20 05:53

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.co

3条回答
  •  长情又很酷
    2021-01-20 06:30

    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 );
    });
    

提交回复
热议问题