Tuesday, 15 June 2010

Node.js Express: passing parameters between client pages -



Node.js Express: passing parameters between client pages -

i have node.js server. lets each client has name saved on variable. switch page , want each client mantain name on variable.

this easy php form, can't see how node.js if form in php, manage send name server:

app.post('/game.html', function(req, res){ var user = req.param('name'); console.log(user); res.redirect('/game.html'); });

but seems complicated resend 1 time again each client it's own. started node.js, guess it's concept error. there easy way pass variable 1 page in client another? thanks.

instead of redirecting static file, have render template ( using engine expressjs supports ):

app.post('/game.html', function(req, res){ var user = req.param('name'); console.log(user); res.render( 'game.html', { user:user } ); });

( note .render requires additonal settings set on app )

now user variable becomes available in game.html template.

node.js express

No comments:

Post a Comment