Skip to content

Instantly share code, notes, and snippets.

@adeleke5140
Last active May 12, 2022 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeleke5140/750729db61032a56af7cab0bd8db661c to your computer and use it in GitHub Desktop.
Save adeleke5140/750729db61032a56af7cab0bd8db661c to your computer and use it in GitHub Desktop.
Submitting a form to a remote server
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