Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

req.flash取不到值

$
0
0
app.use(function(req, res, next){
    console.log('error:' +  req.flash('error').toString());
    res.locals.error = req.flash('error').toString();
    console.log('locals error:' + res.locals.error);
    next();
});

这里面取不到值,赋值的时候可以取到

router.post('/', function (req, res, next) {
    var name = req.body.name;
    if (name.length > 0) {
        new category({ name: name }).save(function (err) {
            res.send('succ');
        });
    }
    else {
        req.flash('error', 'category length need 1 lest');
        //console.log(req.flash('error').toString());
        res.redirect('back');
    }
});

这个怎么解决


Viewing all articles
Browse latest Browse all 14821

Trending Articles