Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page not getting rendered via Express when using post (NodeJS)

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.

like image 542
ali haider Avatar asked May 08 '26 14:05

ali haider


2 Answers

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

like image 110
Aminah Nuraini Avatar answered May 11 '26 02:05

Aminah Nuraini


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

like image 39
TJ Holowaychuk Avatar answered May 11 '26 02:05

TJ Holowaychuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!