【发布时间】:2020-06-03 07:19:40
【问题描述】:
最近chrome在页面卸载或卸载事件前停止支持同步xmlhttprequest https://www.chromestatus.com/feature/4664843055398912
我尝试了这个解决方案Perform an asynchronous service get when closing browser window / tab with Angular,但似乎不适用于最新的 chrome 版本
现在我正在使用这样的 navigator.sendbeacon api
let headers = {
type: 'application/json; charset=utf-8',
'authorization': `bearer ${token}`
}
let blob = new blob([json.stringify({a:"9"})], headers);
navigator.sendbeacon(uri, blob);
Api 正在抛出 401,因此似乎授权不起作用, navigator.sendBeacon 还有其他替代方法吗
【问题讨论】:
标签: asynchronous-postback sendbeacon