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

2019年5月11日
文字数[898文字] この記事は1分7秒で読めます.
ライブドアが提供している天気予報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>