客户端上传的数据
目前测试结果,表单格式或者json格式时,才能被后台解析
nodejs的req对于表单数据只支持一级?严格来说也不是,只是说说现象。
假如数据是user[name]=gubgib
,那么后台就得req.body['user[name]']
来获取
发送
// 表单
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
xhr.send('contetn=123&id=1');
// json
xhr.setRequestHeader("Content-type","application/json; charset=utf-8");
xhr.send('{contetn:123,id:1}');
接收
router.post('/article/save', function (req, res, next) {
// 通过body调用
console.log(req.body.content);
// res.send({});
});