I've this code for login. When I debug the code, I check that the FormData() constructor does not return anything, it is empty. What am I doing wrong? The formLog constant does collect the form data but after passing it to the FormData() constructor, the returned object is empty
<form id="login" method="post" enctype="multipart/form-data" name="login">
<input type="email" name="email" placeholder="Tu email">
<br><br>
<input type="password" name="password" placeholder="Tu contraseña">
<br><br>
<input type="submit" value="Login">
</form>
<script type="text/javascript">
const formLog = document.querySelector('#login')
//Creamos un objeto con los datos del formulario
// AL formLog le agregamos un evento
formLog.addEventListener('submit',event =>{
event.preventDefault()
const data = new FormData(formLog)
fetch('/api/signin',{
method:'POST',
body: data,
})
.then(res => {
res.json()
})
.then(resData => {
localStorage.setItem('token', resData.token)
})
})
</script>