<!-- 给 a 标签一个 id,方便 JS 选择 -->
<a id="dianxueBtn" href="#" class="btn btn-list">点穴</a><script>// 获取 a 标签元素const dianxueBtn = document.getElementById('dianxueBtn');// 监听点击事件dianxueBtn.addEventListener('click', function(event) {// 1. 阻止 a 标签的默认跳转行为 (非常重要!)event.preventDefault();// 2. 准备要发送的数据const postData = {id: 123, // 假设这是用户IDpoint: 'baihui', // 假设这是穴位action: 'dianxue'};// 3. 使用 fetch API 发送 POST 请求fetch('/guanliyuanyemian_dianxue', {method: 'POST',headers: {'Content-Type': 'application/json',// 如果你的后端需要 CSRF 保护,需要添加相应的头部// 'X-CSRFToken': getCSRFToken() },body: JSON.stringify(postData) // 将数据转换为 JSON 字符串}).then(response => {// 4. 处理后端的响应if (!response.ok) {throw new Error('网络响应错误');}return response.json(); // 假设后端返回 JSON}).then(data => {console.log('点穴成功:', data);// 可以在这里给用户一个成功提示,比如弹出一个消息框alert('点穴成功!');}).catch(error => {console.error('点穴失败:', error);alert('点穴失败,请重试!');});});
</script>