ajaxはクロスドメインを許していないのでこうするしかない?わけではないけれど(提供会社による)

20190511

Logging

ライブドアが提供している天気予報APIをJSだけで
なんとか出来ないかと思ったので試してみたけれど無理でしたので、
一回、PHPで読み込んでその情報を取得するという事で解決。
昔はYahooがそういう事を提供してたみたいですが
提供終了してました。

<div style="display: table;">
        <div style="display: table-cell;">
            今日の天気::<br>
            <img id="weather_0" src="">
        </div>
        <div style="display: table-cell;">
            明日の天気<br>
            <img id="weather_1" src="">
        </div>
    </div>

 

<script>
$(function(){
    $.ajax({
        type: 'GET',
        //'http://weather.livedoor.com/forecast/webservice/json/v1?city=390010',
        url: 'https://zip358.com/weather/',
        data:null,
        dataType: 'json'
    }).done(function(data){
        $("#weather_0").attr("src",data.forecasts["0"].image.url);
        $("#weather_1").attr("src",data.forecasts["1"].image.url);
    });
});
</script>

コメントは受け付けていません。

タグ

'src', 0, ajax, API, br, display, div, gt, ID, img, JS, lt, php, style, TABLE, table-cell, weather, Yahoo, クロス, ドメイン, ライブドア, わけ, , 予報, , 今日, 取得, 天気, 情報, 提供, 明日, , 終了, 解決,