Javascript Express-如何从POST表单获取数据
我正在尝试提交表单并将数据保存到数据库中,但无法接收数据 我的路线是:Javascript Express-如何从POST表单获取数据,javascript,node.js,express,post,Javascript,Node.js,Express,Post,我正在尝试提交表单并将数据保存到数据库中,但无法接收数据 我的路线是: routes.post('/new-inventory/:dbname', inventory.store); div(class="popup-content") form(action="/new-inventory/#{dbname}" method="post") div(class="popup-title") span Novo inventário div(class="pop
routes.post('/new-inventory/:dbname', inventory.store);
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
我在控制器中的功能是:
我只是做一个控制台日志,看看是否收到了数据。我知道这是去这个函数,因为显示第一个console.log。req.body
返回{}
store: (req, res) => {
console.log('Storing new inventory...');
console.log(req.body)
},
我的html表单(jade)是:
routes.post('/new-inventory/:dbname', inventory.store);
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
在我的节点服务中,我启动主体解析器
:
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // get information from html forms
我该怎么做?我做错了什么
谢谢只需在每个输入标记中添加
名称
属性只需在每个输入标记中添加名称
属性我认为您没有为每个输入字段添加名称
属性输入使用名称属性我认为您没有为每个输入字段添加名称
属性输入使用名称属性,但如果我添加名称,但第一个输入中禁用的名称除外。解决这个问题的办法是什么?多谢各位@Tlen@user3242861不确定我是否理解,如果第一个输入被禁用,您可以去掉它的名称
,或者去掉它在body请求中的数据。它可以工作,但如果我在禁用的第一个输入之外添加名称。解决这个问题的办法是什么?多谢各位@Tlen@user3242861不确定我是否理解,如果第一个输入被禁用,您可以删除其名称
,或者删除其body请求中的数据。