I am sending user login info with axios in react to the nodejs server. However, my data in nodejs is undefined.
Here is my react js code: -
const reqData = { user: loginID, password }
const loginResult = await axios.post('/login', reqData, {
headers: {
'Content-Type': 'application/json'
}
}
)
Here is my nodejs code: -
app.post("/login", (req, res) => {
const data = req.body;
console.log("Data received: ", data);
res.send("OK")
})
Every time I submit my form, I get undefined in my nodejs server.
it might be possible because your body object isn't a valid json. Try posting something like
const reqData = {
user: loginID,
pass: password
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.