mysql - 为什么这个结果会发生两次?相隔几分钟
问题描述
好消息是,一切都按预期工作。除了,结果发生了两次,我不知道为什么?我已经搜索了代码,没有看到addDocsList
被调用了两次。
这是调用相关 API 路由的方法。它所做的只是调用一个向 mySql 表添加几行的路由:
addDocsList() {
fetch(
API_URL + `/hca/documents/add/${this.state.lastHCA_Id}`,
{
method: "PUT",
body: JSON.stringify({
lastHCA_Id: this.state.lastHCA_Id
}),
headers: { "Content-Type": "application/json" },
}
).then((res) => {
if (!res.ok) {
throw new Error();
}
return res.json();
})
.then((data) => console.log(data))
.catch((err) => console.log(err))
}
它调用这条路线。该路由确实按计划将行添加到表中,大约一分钟后,它会再次执行此操作。但是,无论何时,路由末尾的控制台日志都不会记录。这是否意味着由于某种原因它实际上并没有完成和循环?
app.put("/hca/documents/add/:lastHCA_Id", function (req, res) {
console.log("It is getting to the add docs route.");
const hcaId = req.body.lastHCA_Id;
console.log(`HCA ID: ${hcaId}`);
connection.getConnection(function (err, connection) {
connection.query(
`INSERT INTO hca_docs (hca_id, doc, section)
VALUES
(${hcaId}, 'Personnel Files', 'Location'),
(${hcaId}, 'I-9', 'Location'),
(${hcaId}, 'Time Keeping System', 'Location'),
(${hcaId}, 'Posting Requirements', 'Location'),
(${hcaId}, 'Employee Data Spreadsheet', 'Payroll'),
(${hcaId}, 'Employee Surveys', 'Other')
`
),
function (error, results, fields) {
connection.release();
if (error) throw error;
res.json(results);
console.log("Docs inserted into Table"); <--- This log never happens.
}
});
});
任何帮助表示赞赏。
解决方案
推荐阅读
- reactjs - 如何在 React 函数组件中获取父组件名称
- python - QTableView 将小部件缩小到内容
- java - 在java中存储霍夫曼树
- ios - App Store 中的 WXcode 更新未启动?如何正确更新 Xcode?
- python - 使用 Python 删除部分文本文件
- python - websockets.exceptions.ConnectionClosedError:code = 1006(连接异常关闭[内部]),没有原因Python 3.7 websockets
- javascript - 为什么 GET 请求在 Node.js 中不起作用?
- java - 我应该在服务器或客户端中生成密码/令牌吗?
- html - 如何将 HTML 文件的目录读入 R?
- javascript - 将交互式地图与 React 集成