上图是一个post
表单提交到node
后台,后台使用的express
如何能实现这样的取值方式:
var name = req.body.person.name;
var age = req.body.person.age;
求大神赐教。。
PHP中文网2017-04-17 14:52:38
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.)
ringa_lee2017-04-17 14:52:38
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
Add these two sentences and it will be solved.