APIからJsonのデータを取ってきたのですが、これをfetchAPIで実装する方法を教えてください
JavaScript
1function getRest(lat,lng) { 2 var url = "---apiurl---"; 3 var params = { 4 keyid: "--key--", 5 format: "json", 6 latitude: lat, 7 longitude: lng, 8 range: 3 9 } 10 $.getJSON( url, params, function( result ) { 11 showResult( result ); 12 }); 13}
$getJSONの部分を
JavaScript
1fetch(url).then(function(response) { 2 return response.json(); 3}).then(function(json) { 4 showResult( json ); 5});
に変えてみたのですが、Failed to fetchのエラーが出てしまいます。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/01/23 03:58