说说对 XMLHttpRequest 对象的了解
参考答案
XHR 是浏览器提供的原生 HTTP 请求 API。
关键成员
open(method, url, async, user, pwd)setRequestHeader、send(body)readyState0~4、status、responseText/response- 事件:
onreadystatechange、onload、onerror、ontimeout、onprogress - 配置:
timeout、withCredentials、responseType(json/blob/arraybuffer)、upload.onprogress
特点
支持进度、取消(abort)、自定义头、携带 cookie;不支持 Promise 与流式读取,写法回调嵌套。现多被 fetch / axios(底层仍是 XHR 或 http 模块)替代。