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
Post a Comment