我尝试在注册失败后向用户显示errorMessages
。如果再次访问注册页面,则不会显示errorMessages
阵列。出于某种原因,每次向注册页面发出请求时都会显示req.session.errorMessages
。
module.exports.registration = function(req,res){
if(Array.isArray(req.session.errorMessages) && req.session.errorMessages.length > 0)
res.locals.errorMessages = req.session.errorMessages;
else
res.locals.errorMessages = [];
res.render('registration',{
});
//This line does not seem to reset the array after the response has been rendered
req.session.errorMessages = [];
};
答案 0 :(得分:1)
将其移至render
来电之上。在向用户返回数据后,您似乎无法再更改req
或res
。