You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flask+Jinja模板中点击按钮意外触发打印的问题排查请求

问题原因与解决方法

你遇到的打印触发问题和e.preventDefault()无关,根源是代码里的print(data)语句——这行代码会主动调用浏览器的打印功能,每次点击按钮执行postUpdate()时都会触发它。

解决方法很简单:

  • 如果你是想调试输出数据,把print(data)改成console.log(data);
  • 如果这行只是测试用的冗余代码,直接删除即可。

修改后的相关代码片段:

// Prepare the data to be sent in the request body
var data = {
    fiche: ficheObject
};
// 替换为调试输出或直接删除
console.log(data)
// Send a POST request to the server using the Fetch API
fetch(`/updatefiche/${ficheObject['id']}`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
})
// ... 后续处理逻辑

内容的提问来源于stack exchange,提问作者Nicolas Boudier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 14:22:09