Ashish sah Ashish sah -4 years ago 78
Node.js Question

Not able to use post request in node js

<form class="ui form" action"/submit" method="post">
<div class="field">
<label>Time you gave to your Studies:</label>
<input type="number" name="study" placeholder="Total time given:">
</div>
<div class="field">
<label>Time you gave to your <%= prof %> :</label>
<input type="number" name="proffesion" placeholder="total time given for profession">
</div>
<div class="field">
<label>Time you gave for Sleeping :</label>
<input type="number" name="sleeping" placeholder="total time spended on Sleeping">
</div>
<div class="field">
<label>Time you gave to your games :</label>
<input type="number" name="games" placeholder="total time given for games">
</div>
<button class="ui button" type="submit">Submit</button>
</form>


this was my form:
and I am using express app.js is the main file and index.js containes routes in which I have few routes

router.post('/submit', function(req, res, next) {
var item = {
study: req.body.study,
proffesion: req.body.proffesion,
sleeping: req.body.sleeping,
games: req.body.games
};
console.log(item);
res.render('/index');});


I am not able to post the form data whenever I click submit button it shows 404 error, What wrong I am doing? , How to make a post request and get the forum data?

Answer Source

What you have:

 action"/submit" 

What you should have:

 action="/submit"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download