Using the Yahoo Weather API with JSON and the script tag

前端 未结 3 1548
自闭症患者
自闭症患者 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:31

    Here is some code

    $(document).ready(DocReady);
    
    function DocReady()
    {
        jQuery.support.cors = true;
        var Result = $.getJSON("http://weather.yahooapis.com/forecastjson?w=9807", "",
            function (data)
            {
                $("body").append("Sunrise: " + data.astronomy.sunrise + "
    "); $("body").append("SuntSet: " + data.astronomy.sunset + "
    "); }); }

提交回复
热议问题