node.js - nodejs处理post表单数据的问题
ringa_lee
ringa_lee 2017-04-17 14:50:38
0
4
905


上图是一个post表单提交到node后台,后台使用的express

如何能实现这样的取值方式:

var name = req.body.person.name;
var age = req.body.person.age;

求大神赐教。。

ringa_lee
ringa_lee

ringa_lee

reply all(4)
阿神

app.use(bodyParser.json());

Ty80

If you directly use the form element to send http requests to submit form data, use name="person[name]". Actually, a person object will not be automatically generated when sending the request. If you want to use req in node. body.person.XXX to get the submitted content, or use js to submit the form. (If there are not many submitted items, you can list them one by one. If there are many, just traverse this form to get the value.)

左手右手慢动作
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

Add these two sentences and it will be solved.

巴扎黑

No need to bother, just req.body.xx can get the value!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!