app.js
var flash = require('connect-flash');
app.use(flash());
app.post('/loginaction',function(req,res){
var user = new User(req.body.user);
user.save(function(err){
if(!err){
req.flash('info','flash!!save!!');
res.redirect('/');
}else{
res.redirect('/login');
}
});
});
jade
form(method = 'post' ,action='/loginaction')
fieldset
legend register a user
div.clearfix
label Login
div.input
input(name='user[name]',class='xlarge')
input(name='user[pwd]',type='password',class='xlarge')
div.actions
input(type='submit',value='save',class='btn primary')
input(type='reset',value='reset',class='btn primary')
input(type='button',value='cancel',class='btn primary')
script alert(typeof flash);
script alert(flash.info);
0.学习阶段,我只想在登陆成功的时候告诉用户一下。。。顺便存到session中保存登陆信息 1.flash.info undefined 。。。请问各位大牛 问题出在哪? 2.node 3.X以后req.flash被req.session.messages = [‘foo’] ;替代,但是这玩意照着网上说的设置了
app.use(express.cookieParser());
app.use(express.session({
secret : "hardwork!"
}));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.post('/loginaction',function(req,res){
var user = new User(req.body.user);
user.save(function(err){
if(!err){
req.session.messages = ['foo'] ; // jade页面上如何拿到呢?????
res.redirect('/');
}else{
res.redirect('/login');
}
});
});
5 回复