Monday, 12 June 2017

HTML form post to node.js file keeps loading

I'm trying to do a simple form submission on my server that posts some contact information. I receive the information successfully on my node.js file that runs the server, but after I click submit the page tries to load action page and eventually fails.

HTML

<form id = "form" action="/", method = "post">
....
<button type="submit" form="form" value="Submit">Submit</button>
</form>

Node.js

app.post('/', function(req, res) {
.......

I'm using express to display static html and image files, and i'm connecting to localhost:8080/MyWebsite.html. But after I click the submit button I'm redirected unsuccessfully to localhost:8080, where chrome says "this site cannot be reached". Can someone explain to me exactly what's going on here, and how I can simply submit the form and stay on the page without any other issues?



via Sherman Luo

No comments:

Post a Comment