Why is my formData appearing empty when sent to my express+mongodb server? I'm having some issues with querySelector and addEventListener, but for now that's manageable. However, I am struggling to find a way to successfully send all the values of my form to the server. Can anyone offer some guidance?
document.querySelector('#enviar-cadastro').addEventListener('click', Register);
Register('http://localhost:5000/usuario/novo')
.then(response => console.log(response.json()))
.then(data => console.log(data))
.catch(error => console.log(error));
function Register(url) {
const formData = new FormData(document.querySelector('#signup'))
return fetch(url, {
method: 'POST',
body: JSON.stringify(formData),
headers: {
"Content-Type": "application/json"
}
})
};