簡體   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