DOMcss
BOMhtml
事件node
Ajax(Asynchronous JavaScript + XML)ios
function ajax(url) { const p = new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); // 建立xhr實例 xhr.open('get', url, true); // 定義請求 xhr.onreadystatechange = function () { if(xhr.readyState === 4) { // 數據響應階段0-4,未初始化到完成接收全部響應 if(xhr.status === 200) { // HTTP狀態碼,數據響應成功與否 resolve( JSON.parse(xhr.responseText) // 響應數據 ) } else if (xhr.status === 404) { reject(new Error('404 not found')) } } } xhr.send(null); // 發送請求 }) return p; }
fetch('/url/bar') .then(response => { console.log(response.status); console.log(response.text()); })
存儲web