Skip to content

Commit fd3e0dc

Browse files
committed
update
1 parent 211d853 commit fd3e0dc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

NET网络请求/Fetch API/如何在关闭浏览器标签前,可靠地发送 HTTP 请求.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
font-size: 16px;
1313
line-height: 1.5;
1414
h3 {
15+
color: red;
1516
margin: 0;
1617
line-height: 0;
1718
}
1819
}
20+
button {
21+
padding: 10px 20px;
22+
font-size: 16px;
23+
}
1924
</style>
2025
</head>
2126
<body>
@@ -93,8 +98,8 @@ <h3>解决方案二:fetch() 与 keepalive: true</h3>
9398
// 使用 sendBeacon 发送数据
9499
// 该方法会返回 true (成功加入队列) 或 false (数据过大或格式错误)
95100
const success = navigator.sendBeacon(
96-
"http://127.0.0.1:666/api/v1/insert?" + params.toString(),
97-
body
101+
"http://127.0.0.1:666/api/v1/insert?" + params.toString()
102+
// body // 传递数据
98103
);
99104

100105
if (success) {
@@ -151,7 +156,7 @@ <h3>解决方案二:fetch() 与 keepalive: true</h3>
151156
// 在这种情况下,我们通常不发送信标
152157
return;
153158
}
154-
// fetchSendData();
159+
fetchSendData();
155160
});
156161

157162
document.querySelector("#fetch-btn").onclick = function () {

0 commit comments

Comments
 (0)