1
I have a small form with login and password whose data I need to be sent to a route X via POST. For this, I used AJAX and to make sure that the data was being sent, I used the Success function to show a feedback log. The problem is, on the route responsible for receiving this data, I can’t access it. I’m using Express and as far as I know, to access the data you must use req.body.nameDado, but when doing this the value returned is Undefined. How can I fix this?
Customer Javascript for sending data
$("#btn-signin").click((e) => {
(async () => {
try {
const login = $('#loginform').val()
const password = $('#passwordForm').val()
await $.ajax({
url: "http://localhost:8081/Auth/check-signin",
method: "POST",
data: {
login: login,
password: password
},
success: console.log('Dados enviados!')
})
const res = await apiResponse()
if (res.errorMessage) {
alert(res.errorMessage)
}
} catch (error) {
console.log(`Error: ${error}`)
}
})()
})
In case my answer does not resolve, I suggest you edit the post including the code of your back-end. That way other people can more easily identify where the error is.
– Allan Juan