So, when i try to append a data to a formData, it does nothing.
Js code:
document.querySelector("#regForm").addEventListener('submit', e => {
e.preventDefault();
let username = document.querySelector("#username").value;
let formData = new FormData();
formData.append('username', 'username');
console.log(formData)
const request = new XMLHttpRequest();
request.open("POST", '/register');
request.send(formData);
})
Can you help me? Thanks!
Edit: Screenshot
>Solution :
You can use FormData.entries
Since FormData.entries return iterator
You can transform it to array using spread operator
If you want the result to be object you need to use the reduce function
const formData = new FormData()
formData.append('username', 'username')
formData.append('password', 'password')
const result = [...formData.entries()].reduce((acc, val) => {
acc[val[0]] = val[1]
return acc
}, {})
console.log(result)