当我通过 Express 对 Postgres 运行 PUT 查询时,我收到以下错误。
错误:整数的输入语法无效:"所有调用">
它似乎引用了router.put函数中的这段代码。response.redirect('all-calls'(.数据库中的数据正在正常更新。
这是我创建的第一个 POST 请求。所有其他重定向都是POST,并且response.redirect('all-calls'(在它们上运行良好。
有问题的 PUT 路由:
router.put('/update-call-simple/:id', (request, response, next) => {
console.log(request.body)
const { id } = request.params;
const { organisation_id, caller_name, call_contents, support_agent, priority, category, id_vendor } = request.body;
pool.query('UPDATE calls SET id_organisation=($1), caller_name=($2), call_contents=($3), support_agent=($4), priority=($5), category=($6), id_vendor=($7) WHERE calls_id=($8)',
[organisation_id, caller_name, call_contents, support_agent, priority, category, id_vendor, id],
(err, res) => {
if (err) return next(err);
response.redirect('all-calls');
})
})
运行良好的 PUT 路由示例:
router.post('/new-call-simple', (request, response, next) => {
const { organisation_id, caller_name, call_contents, support_agent, priority, category, id_vendor } = request.body;
pool.query('INSERT INTO calls (id_organisation, caller_name, call_contents, support_agent, priority, category, id_vendor, date_time) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)',
[organisation_id, caller_name, call_contents, support_agent, priority, category, id_vendor, Date.now()],
(err, res) => {
if (err) return next(err);
response.redirect('all-calls');
}
)
})
您使用的是相对路径,并且 express 无法解析相对于/update-call-simple/:id
all-calls
路径。除非您有/update-call-simple/:id/all-calls
路由,否则重定向将不起作用。快递可能假设这是一个status-code
输入。
使用/
使路径相对于根。
例如,在你有一条路线中:
router.put('/path/to/somewhere' ...
并在其他地方的代码中重定向到此页面:
...
res.redirect('/path/to/somewhere')