Js筆記 AJAX Posted on 2020-08-17 Edited on 2020-12-24 In JavaScript AJAXXMLHttpRequestopen 格式 onlaod確定資料回傳,執行以下函式 123456789function getData() { let xhr=new XMLHttpRequest(); xhr.open('get',url,true); xhr.send(null); console.log(xhr.responseText) xhr.onload=function () { let data1 = JSON.parse(xhr.responseText) return data=data1.ROOT.RECORD}} asios 1234567// axiosfunction getData(){ axios.get(url) .then(function (response) { return data=response.data.ROOT.RECORD });} jQuery 12345678910111213function getData() { $(document).ready(function () { $.ajax({ type: "get", url: url, data: "data", dataType: "json", success: function (response) { return data=response.ROOT.RECORD } }); });} 範例