页面为
<form action="/menu-add" method="post" id="form-admin-add">
...
后台为
router.post('/menu-add', function (req, res, next) {
console.log(req.body);//此处为undefined
req.on('data', function (chunk) {
req.rawBody += chunk;
});
req.on('end',function(chunk){
console.log(req.rawBody)
}
});
express app设置
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
输出
undefined
undefinedadmin-role=0&menu-code=22&menu-name=22&menu-page=22&level=1
网上直接的办法为什么获取不到呢,反而必须要用请求流的方式才能获取
你全局按安装express,然后使用express -e 创建express模板项目,运行试试,看看会不会出现你这问题.
应该是你配置不对,但是就这点信息,没有办法知道是你哪里的配置出问题了