AjaxでJSON取得
req.openの2つ目は非同期のフラグ、req.sendはPOSTの場合データが入る。
const req = new XMLHttpRequest(); req.open("GET", "myjson.json", true); req.onreadystatechange = () => { if (req.readyState === 4 && req.status === 200) { const jsonText = req.responseText; const json = JSON.parse(jsonText); this.resultAjax = jsonText; } } req.send(null);