html - `Confirm Form Resubmission` issue on page rendered thru app.post('/', in expressjs -


html contains

form(name="form", action="/", method="post")   button(type='submit') submit 

express server contains:

app.post('/', function(req, res){      res.render('home', {user: req.body}); }); 

as expected home.jade rendered in browser. when refresh home.jade file @ http://localhost:3000 asks confirm form resubmission want rid of - confirm form resubmission!

the home.jade file simple file containing simple text.

the problem isn't caused code, browsers want post again when you've received response post. common way solve issue redirect same page.

app.post('/', function(req, res){      res.redirect('/'); }); 

now when refresh browser refetch '/' instead.

update reflect updated question

to render data posted on redirected page, 1 can use sessions.

app.use(express.cookiesession());  app.post('/', function(req, res){   req.session.user = req.body;   res.redirect('/'); }); 

and in middleware '/' have make sure use parameter

app.get('/', function(req, res){   res.render('home', { user: req.session.user }); }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -