0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【脱jQuery】AjaxをFetch APIで実現する

Posted at

ナウいAjaxのやり方として、Fetch APIのテストソースを書きました。
呼び先のAPIは天気を取得するOpenWeatherMapを使用しています。

snippet.js
var API_KEY = 'APIキーを設定';
var lon = '141.355539';
var lat = '43.067885';
var URL = `http://api.openweathermap.org/data/2.5/forecast?lat=${lat}&lon=${lon}&cnt=1&units=metric&APPID=${API_KEY}`;


(async ()=>{
    try{
        var res = await fetch(URL);
        var data = await res.json();
        console.log(JSON.stringify(data));
    }
    catch(err){
        console.log(err);
    }
})();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?