当前位置:网站首页>在 关闭页面/卸载(unload)文档 之前向服务器发送请求
在 关闭页面/卸载(unload)文档 之前向服务器发送请求
2022-08-11 04:47:00 【qq_46302247】
官方介绍:https://developer.mozilla.org/zh-CN/docs/Web/API/Navigator/sendBeacon
可参考:https://www.jianshu.com/p/04e88271a8f2?from
终极解决方案:
window.addEventListener("beforeunload", (e) => {
const data = {
name: "tm"};
window.navigator.sendBeacon("http://127.0.0.1:1891/loginout", JSON.stringify(data));
});
不管是刷新页面还是关闭页面,后台都能接收到前端发送过来的请求,完美实现需求。
边栏推荐
- 交换机和路由器技术-30-标准ACL
- The principle, architecture, implementation, practice of "transfer" and "search", no need to be afraid of interviews
- 洛谷P2370 yyy2015c01 的 U 盘
- Mysql:设置主键自动增长起始值
- 【Web3 系列开发教程——创建你的第一个 NFT(9)】如何在手机钱包里查看你的 NFT
- 延长经济保险(jeecgboot)
- 一种基于共识机制的数字集群终端防失控方案研究
- 【小记】BatchSize的数值是设置的越大越好吗
- MySQL database storage engine and database creation, modification and deletion
- 交换机和路由器技术-32-命名ACL
猜你喜欢
随机推荐
交换机和路由器技术-27-OSPF路由重分发
【FPGA教程案例50】控制案例2——基于FPGA的PD控制器verilog实现
The priority queue
交换机和路由器技术-31-扩展ACL
华南师范宋宇老师课堂对话论文翻译
北湖区燕泉街道开展“戴头盔·保安全”送头盔活动
0 Basic software test for career change, self-study for 3 months, 12k*13 salary offer
澳大利亚网络空间安全体系建设论析
[Web3 series development tutorial - create your first NFT (9)] How to view your NFT in the mobile wallet
Selenium自动化测试框架工作原理你明白了吗?
关于数据分页显示
交换机和路由器技术-21-RIP路由协议
Layered Architecture & SOA Architecture
leetcode 9. 回文数
嵌入式分享合集33
Provincial level of Echart maps, as well as all prefecture-level download and use
1815. Get the maximum number of groups of fresh donuts state compression
【ImageNet】数据集1000个类的名称
JVM 垃圾回收的概述与机制
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing