Long time, first time. I am new to learning node JS, Javascript, express, etc. and have been dealing with a problem for three days and counting. Hoping for some kind help here.
I have a view (called 'standings' view) where the user fills in an HTML form entering their username and bunch of team names.
- I handle the post request using express and save the data in mongodb
- The request contains a username field which can be referenced by 'req.body.username' inside the express app.post method.
What I am trying to do is capture this 'req.body.username' from the POST request and use it in another JS file (called 'thankyou.js') which would be the config file for a "thankyou" view. In other words, I am looking for a way to somehow reference the 'req.body.username' parameter directly without having to go back to the DB and in my "thankyou" view I want to say something like:
"Thank you" + <%= req.body.username %> + "for contacting us".
What would be the best approach to accomplish this? I have thought of and researched the following but not quite sure how to implement:
- Somehow export 'req.body.username' property in my standings JS file and require/reference it in the thankyou JS file.
- Using query strings to pass the 'req.body.username' in standings.js to the thankyou view.
Here is my express app.post method which handles the POST call from the user for the 'standings' view:
app.post('/standings', urlencodedParser, function(req, res){
var newStandings = standingsModel.update({ username: req.body.username}, req.body, {upsert: true}, function(err,data){
if (err) throw err;
res.json(data);
})
});
Thanks in advance.
via tshayan
No comments:
Post a Comment