文档链接:https://developer.mozilla.org/zh-CN/docs/Web/API/Navigator/sendBeacon
window.addEventListener("pagehide", () => {
let form = new FormData();
form.append('data',data)
//navigator.sendBeacon(`${location.host.substring(0,location.host.indexOf(':'))}/v2/user/stoping/`,form)
navigator.sendBeacon(url,data)
});
参数:
url
url 参数表明 data 将要被发送到的网络地址。
data 可选
data 参数是将要发送的 ArrayBuffer、ArrayBufferView、Blob、DOMString、FormData 或 URLSearchParams 类型的数据。
请求方式:默认为post请求