HTML 单页面按钮,限制 IP 请求次数 - 每小时 3 次
<!DOCTYPE html>
<html>
<head>
<title>限制 IP 请求次数</title>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.btn {
padding: 10px 20px;
background-color: #4CAF50;
color: #fff;
font-size: 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div class='container'>
<button class='btn' onclick='sendPost()'>点击发送 Post 请求</button>
</div>
<pre><code><script>
function sendPost() {
const xhr = new XMLHttpRequest();
// 设置请求方法和请求地址
xhr.open('POST', 'http://localhost:3000', true);
// 设置请求头
xhr.setRequestHeader('Content-Type', 'application/json');
// 设置请求体
xhr.send(JSON.stringify({}));
// 监听请求状态变化
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const res = JSON.parse(xhr.responseText);
alert(res.message);
}
}
}
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lEgq 著作权归作者所有。请勿转载和采集!