繁体   English   中英

Express-如何从POST表单获取数据

[英]Express - How to get data from POST form

我正在尝试提交表单并将数据保存在数据库中,但是我无法接收数据。

我的路线是:

routes.post('/new-inventory/:dbname', inventory.store);

我在控制器中的功能是:我只是做一个控制台日志以查看是否接收到数据。 我知道去这个功能是因为显示第一个console.log。 req.body返回{}

store: (req, res) => {
    console.log('Storing new inventory...');
    console.log(req.body)
  },

我在html(jade)中的表单是:

div(class="popup-content")
  form(action="/new-inventory/#{dbname}" method="post")
    div(class="popup-title")
      span Novo inventário
    div(class="popup-data")
      div(class="form-group")
        label(for="inventory-description") Descrição
        input(type="text" id="inventory-description" value="#{description}" class="form-control" disabled)
      div(class="form-group")
        label Armazém
        select(class="form-control" id="wharehouse-select")
          each whare, i in wharehouse
            option(value="#{whare.szzstamp}" data-option="#{whare.armazem}") #{whare.armazem} - #{whare.zona}
      div(class="form-group")
        label(for="inventory-date") Data
        input(type="text" id="inventory-date" class="form-control")

    div(class="popup-button")
      div(class="btn-submit")

        button(type="submit") Criar
        div(class="close-btn")
          span Cancelar

在我的节点服务中,我启动body-parser

app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // get information from html forms

我怎样才能做到这一点? 我做错了什么?

谢谢

只需在每个输入标签中添加name属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM