当前位置:网站首页>在 关闭页面/卸载(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));
});
不管是刷新页面还是关闭页面,后台都能接收到前端发送过来的请求,完美实现需求。
边栏推荐
- 交换机和路由器技术-26-OSPF末梢区域配置
- 洛谷P4847 银河英雄传说V2
- How to add icons to web pages?
- Three 】 【 yolov7 series of actual combat from 0 to build training data sets
- 如何缓解压力、拒绝内耗【1】
- 交换机和路由器技术-32-命名ACL
- 视觉任务种常用的类别文件之一json文件
- 0 Basic software test for career change, self-study for 3 months, 12k*13 salary offer
- Listen to pull out U disk inserted into the message, U disk drive
- 《卫星界》刊评“星辰大海”计划:孙宇晨为太空旅游带来新的机遇
猜你喜欢
随机推荐
如何缓解压力、拒绝内耗【1】
Add PRODUCT_BOOT_JARS and classes to provide jar packages to applications
Switch---Spanning Tree---Three-layer Architecture Summary
交换机和路由器技术-22/23-OSPF动态路由协议/链路状态同步过程
Resize() usage row pit in vector
Object Creation and Display Transformation
洛谷P4560 Wall 砖墙
"3 Longest Substring Without Repeating Characters" on the 17th day of LeetCode brushing
About data paging display
【组成原理 九 CPU】
洛谷P4032 火锅盛宴
【FPGA教程案例49】控制案例1——基于FPGA的PID控制器verilog实现
Use Navicat Premium to export database table structure information to Excel
The sword refers to offer_abstract modeling capabilities
leetcode 9. 回文数
Three 】 【 yolov7 series of actual combat from 0 to build training data sets
洛谷P5139 z小f的函数
0基础转行软件测试,自学3个月,浅拿12k*13薪offer
2022新员工公司级安全教育基础培训(118页)
Events and scheduled tasks in Mysql









