-
-
Save WesleySmits/0877cdf65a3699bb825977c34c64828b to your computer and use it in GitHub Desktop.
FormData: Fetch
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 newsletterForm = document.getElementById('newsletter-form'); | |
newsletterForm.addEventListener('submit', () => { | |
const formData = new FormData(newsletterForm); | |
fetch('/some/api/endpoint', { | |
method: 'post', | |
body: formData | |
}) | |
.then((response) => response.json()) | |
.then((result) => { | |
console.log('Success:', result); | |
}) | |
.catch((error) => { | |
console.error('Error:', error); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment