Last active
May 12, 2022 16:17
-
-
Save adeleke5140/750729db61032a56af7cab0bd8db661c to your computer and use it in GitHub Desktop.
Submitting a form to a remote server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myForm = document.getElementById('my-form'); | |
const url = 'http://localhost:8080/'; | |
myForm.addEventListener('submit', async event => { | |
event.preventDefault(); | |
const formData = new FormData(myForm); | |
const response = await fetch(url, { | |
method: 'post', | |
body: formData | |
}); | |
const result = await response.text(); | |
alert(result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment