As the title says, I am trying to capture user's input through an HTML form and on submit, POST their data to an API.
I can successfully POST and get a response from the API, however none of my form data is being attached (at least I believe this is the ongoing issue).
Since this is practice I am using a free post API I found online at https://reqres.in/. All help is appreciated!
HTML
<form id="myForm">
<label for="myName">Send me your name:</label>
<input id="myName" name="name" value="Alex">
<br>
<label for="userId">your id:</label>
<input id="userId" name="id" value="123">
<br>
<label for="myJob">your name:</label>
<input id="myJob" name="job" value="Web Dev">
<br>
<input id="postSubmit" type="submit" value="Send Me!">
</form>
And here is my JavaScript
const thisForm = document.getElementById('myForm');
thisForm.addEventListener('submit', async function (e) {
e.preventDefault();
let response = await fetch('https://reqres.in/api/users', {
method: 'POST',
body: new FormData(thisForm)
});
let result = await response.json();
alert(result.message)
console.log(result)
});