javascriptでのhttp通信メモ
古いやり方
XMLHttpRequestを使う const url = 'urlを指定'; const request = new XMLHttpRequest(); request.open("GET", url); request.addEventListener("load", (event) => { 処理 }); request.send();
新しいやり方
fetchを使う const url = 'urlを指定'; fetch(url) .then(response => response.json()) .then(json => { jsonでの処理 });
とりあえずメモ
これから使ってみる
追記
fecthよりも良いaxiosってのがあるらしい <script src="https://unpkg.com/axios/dist/axios.min.js"></script> axios.get(url) .then(response => response.data) .then(json => { jsonでの処理 });