点击登录就提示这个错误,但找不到原因
TypeError: **Cannot read property 'username' of undefined**
login.js
前台js:获取输入的username password 拼成一个数组传给后台,
巴扎黑2017-04-17 14:45:25
First: You should make sure ajax method is same as routers' method
Second: You should make sure parse the data in body.
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
怪我咯2017-04-17 14:45:25
body
The data cannot be obtained.
It may be that header
is application/x-www-form-urlencoded
, and datatype
is caused by JSON
.
If you want to obtain JSON
data in the background, you need to ensure that the middleware of express
is used
app.use(bodyParser.json());
阿神2017-04-17 14:45:25
How did the original poster solve it? I encountered the same problem
TypeError: Cannot read property 'name' of undefined