Node.js reported an error: cannotreadproperty ‘username’ of undefined

  node.js, question

Click login to prompt this error, but the reason cannot be found.

TypeError: **Cannot read property 'username' of undefined**

clipboard.png

login.js

clipboard.png

Front js: Get the input username password and spell it into an array to pass to the back.

clipboard.png

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
 }));