DOM
BOM
事件
Ajax(Asynchronous JavaScript + XML)
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()); })
存储
原文:https://www.cnblogs.com/nicolelhh/p/14255630.html