无法使用nodejs获取表单数据

问题描述 投票:0回答:0

我正在尝试在 mongodb 中保存帖子的正文。

每次我只得到这个结果。

{ _id: new ObjectId("63f222995b85f79e258642c4"), __v: 0 }

HTML 表单代码

<form action="/" method="post">
    <div class="item11 bg12">
        <input id="inph" type="text" class="in bg1" placeholder="Phone number, username or email address">
    </div>
    
    <div class="item11">
        <input id="inpass" type="text" class="in bg1" placeholder="password">
    </div>
    
    <div class="item11">
        <button type="submit" id="btlog" class="in bg2">Log in</button>
    </div>
</form>

节点js代码

const credential=mongoose.Schema({username:String,password:String});const cr_den=mongoose.model('instagram_clone',credential);
app.get('/',(req,res)=>{res.render('index.pug');})
app.post('/',(req,res)=>{var data=new cr_den(req.body);data.save().then(()=>{console.log("response Noted..!!");console.log(data);}).catch(()=>{console.log('Failed To Save Data...!!!')})res.render('index.pug');})

结果应该是

{ _id: new ObjectId("63f222995b85f79e258642c4"), username:"xyz",password:"xyz",__v: 0 }
html node.js mongodb forms post
© www.soinside.com 2019 - 2024. All rights reserved.