【问题标题】:Getting unidentified from bodyParser从 bodyParser 获取身份不明
【发布时间】:2020-04-24 02:29:55
【问题描述】:

我刚开始学习 nodejs + express + 车把,我的帖子遇到了困难。这是我收到的请求正文,我似乎无法使用 req.body.province 和 req.body.municipality 获取“省和市”数据,但我可以。

{
'province ': 'ALBAY',
  'municipality ': 'BACACAY',
  bearing: '>=1 and <=20'
}

这就是我从我的城市和省的表格中获取数据的方式。

<div class="form-group">
<label for='municipality'>Municipality</label> <select type= "text" name="municipality " class="form-control"> {{#each municipality}}
 <option>{{municipality}}</option> 
{{/each}} </select>

这是为了承受。

<div class="form-group">
<label for="bearing">Bearing Trees</label> <select type="text" name="bearing" class="form-control">
 <option>>=1 and <=20</option>
<option>>=21 and <=50</option>
<option>>=51 and <=100</option> <option>>100</option> </select> </div>

我现在有点卡住了,我需要你的帮助。谢谢

【问题讨论】:

    标签: html node.js express handlebars.js body-parser


    【解决方案1】:

    据我所知,城市和省对应的键在末尾包含一个空格。

    在对象内部,所有键都是字符串类型,这意味着除非您使用符号,否则会包含空格。

    对于您的问题,这更像是一个错字。

    您的对象应如下所示:

    {
        province: 'ALBAY',
        municipality: 'BACACAY',
        bearing: '>=1 and <=20'
    }
    

    【讨论】:

    • 哦。所以这就是为什么。我没有注意到名字中的那个小空间。我已经被困在这里几个小时只是因为那个错误。非常感谢!
    • 我很高兴啊 ;)
    • 您必须更新表单中的名称,这就是空格的来源
    • 我只是这样做了,最后在我的应用程序中取得了进展。我现在可以使用 bodyParser 解析数据。谢谢。
    • 很高兴,您现在可以将问题标记为已解决
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 2019-06-17
    • 1970-01-01
    相关资源
    最近更新 更多