如何清除req.session.array?

时间:2014-06-26 18:05:27

标签: javascript node.js express

我尝试在注册失败后向用户显示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 = [];

};

1 个答案:

答案 0 :(得分:1)

将其移至render来电之上。在向用户返回数据后,您似乎无法再更改reqres