【发布时间】:2020-09-29 12:22:17
【问题描述】:
我的代码是
main.post('/userlist', function(req, res, next) {
// where did you get this?
// var db = req.db;
var query = connection.query("SELECT name,zaman,giriscikis FROM giriscikis where date_format(zaman,'%Y-%m-%d') between ? and ?", [req.body.bas, req.body.bitis], function(err, result) {
if (err) throw err;
console.log(result);
res.send(httpResponse(result));
return res.redirect('/zamansorgu');
//console.log(req.body.bas)
//console.log(req.body.bitis)
});
});
我想从数据库中获取数据并重定向到代码中的同一页面(zamansorgu.html)
但我得到一个错误
Cannot set headers after they are sent to the client
我该如何解决这个问题
感谢您的帮助
【问题讨论】:
-
您不能同时使用 res.send 和 res.redirect。您只能使用其中一种。调用 res.send 后,连接将关闭,因此之后调用 res.redirect 将无法正常工作,因为客户端已断开连接。