I am trying to receive an input from an html form in my js file.
HTML
<form action='/bmicalc' method="post">
<input type='text' name='h' placeholder='Height'>
<input type='text' name='w' placeholder='Weight'>
<button type='submit' name='sub'>Calculate</button>
</form>
JS
const express=require('express');
const app=express();
app.get('/',function(req,res){
res.send('<h1>Hello There!<h1>');
});
app.get('/bmicalc',function(req,res){
res.sendFile(__dirname+'/bmicalc.html');
})
app.post('/bmicalc',function(req,res){
console.log(req.body.h);
});
app.listen(3000,function(){
console.log("Started server on port 3000");
})
However I'm always getting the following error:
TypeError: Cannot read property 'h' of undefined
Can someone please help point out the mistake?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…