문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top