Reputation: 20202
I am using Express v.2.4.6 (Node.js - v.0.6.2). I am trying to render (or redirect to) a new page once POST is called (as opposed to GET). I am able to render/redirect when GET is called. However, I cannot seem to render a page when POST is called in Express. I am not sure if this is even possible though the guide on the Express site does mention an example where you can redirect once POST is called. The relevant code is given below (client is sending the form in JSON). I can parse through the JSON message successfully in Node.j.
Sample route:
app.post('/signup', function(req, res){
res.redirect('index');
//res.render('index');
});
No exceptions are thrown, but the index page does not get rendered nor redirected. Any feedback will be appreciated.
Upvotes: 3
Views: 4456
Reputation: 26
res.redirect('/')
is most likely what you wanted there, but you can render in any route, redirecting is just a convention that most people use
Upvotes: 1
Reputation: 19156
Maybe you call it from $.ajax
from client-side
It works well if you call it from server-side
Please refer to this question. Express.js Won't Render in Post Action
Upvotes: 2