javascript - 无法在node js中使用post请求

标签 javascript node.js mongodb express

<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="profession" 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 spent 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>

这是我的表格,我正在使用 Express。 app.js 是主文件,index.js 包含我几乎没有路由的路由:

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

每当我点击提交按钮时,我都无法发布表单数据,它显示404错误,我做错了什么? , 如何发出post请求并获取论坛数据?

最佳答案

你拥有什么:

 action"/submit" 

你应该拥有什么:

 action="/submit"

关于javascript - 无法在node js中使用post请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44487202/

相关文章:

javascript - 将数据从mysql数据库导入到现有的html5表中

ruby-on-rails - 使用 Rails 搜索 MongoDB

mongodb - 在聚合管道、MapReduce 或 runCommand 中使用存储的 JavaScript 函数

node.js - 在 NodeJs 中处理 Mongodb 全局连接的最佳方法是什么

javascript - Javascript中的Javascript模块

javascript - 在 Node.js 中使用 mongoose 条件更新数组

javascript - 如何根据属性值制定在运行时添加 Angular 部分的指令

javascript - Chrome 开发工具中 "Clear Site Data"的 JavaScript 等价物是什么?

javascript - 确定http请求的发送者

node.js - 与单个 Redis channel 相比,使用 Redis channel 的成本是多少