XMLHttpRequest(XHR)对象用于与服务器交互。通过 XMLHttpRequest 可以在不刷新页面的情况下请求特定 URL,获取数据。这允许网页在不影响用户操作的情况下,更新页面的局部内容。
兼容性高
open()是准备工作,尚未发送.send是发送,response是响应
xhr = new XMLHttpRequest()
xhr.open('get','https://www.xxx.com/x/api/struggle',1)
xhr.send()
console.log(xhr.response)
整个过程是一个发送请求的过程.
请求头加密可能会在,open和send之间进行操作.
jquery的ajax请求,原理上还是XMLHttpRequest方法,源码
axios:
script src=“https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js”>
在浏览器上面使用需要导入.
axios.get()
请求在发送时是有延迟的.
是一个完全异步的库. 并不支持同步方案.
this.interceptors是一个点.
axios本质还是 XMLHttpRequest
fetch:兼容性差 请求是异步的 跟axios像.
// var url = "xxxx";
// var promise = fetch(url).then(function(response) {console.log(window.r = response)})
// var text = window.r.text()
worker实现多线程.
const work = new Worker("xxxx");
WebSocket
var ws = new WebSocket("xxx")