Created
May 15, 2025 03:22
-
-
Save librz/7d2590afbeb18a2490ff798d43ed0ed7 to your computer and use it in GitHub Desktop.
Prevent default form submit & manually submit using fetch
This file contains hidden or 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
form.addEventListener('submit', async (e) => { | |
e.preventDefault(); | |
const formData = new FormData(form); | |
const response = await fetch(form.action, { | |
method: form.method, | |
body: formData | |
}); | |
// handle response... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment