英文:
Getting unidentified from bodyParser
问题
我正在开始学习Node.js + Express + Handlebars,但在处理我的POST请求时遇到了困难。这是我接收到的请求体,我似乎无法通过req.body.province
和req.body.municipality
来获取“省份和市镇”数据,但对于bearing,我可以。
{
'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>
以及用于bearing的部分。
<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>
我现在有点卡住,需要您的帮助。谢谢!
英文:
I'm just starting learning nodejs + express + handlebars and I'm having a difficult time with my post. This is the request body that I am receiving and I can't seem to get the "province and municipality" data using req.body.province and req.body.municipality, but with bearing, I can.
{
'province ': 'ALBAY',
'municipality ': 'BACACAY',
bearing: '>=1 and <=20'
}
This is how I get my data from my form for municipality and province.
<div class="form-group">
<label for='municipality'>Municipality</label> <select type= "text" name="municipality " class="form-control"> {{#each municipality}}
<option>{{municipality}}</option>
{{/each}} </select>
And this is for bearing.
<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>
I'm kinda stuck now and I need your help. thanks
答案1
得分: 0
从我所看到的,与市和省对应的键末尾包含一个空格。
在对象内,所有的键都是字符串类型,这意味着空格是包含在内的,除非你使用一个符号。
对于你的问题,更多是拼写错误而不是其他什么。
你的对象应该像这样:
{
province: 'ALBAY',
municipality: 'BACACAY',
bearing: '>=1 and <=20'
}
英文:
From what i can see, the keys corresponding to municipality and province contains a space at the end.
Inside an object all the keys are of type string, which means the space is included unless you are using a symbole.
For your question it's more a typo that anything else.
your object should looks like this :
{
province: 'ALBAY',
municipality: 'BACACAY',
bearing: '>=1 and <=20'
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论