Last active
September 28, 2021 05:15
-
-
Save yushanwebdev/dcab9c3da5dd8894ac2efc7df8e71207 to your computer and use it in GitHub Desktop.
JavaScript Fetch API post data not added to the Request body issue fixed by setting headers using `new Headers()`
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
// https://github.com/matthew-andrews/isomorphic-fetch/issues/34 | |
// This helped me to solve the issue. | |
const myHeaders = new Headers(); | |
myHeaders.append('Content-Type', 'application/json'); | |
fetch('/contact-form', { | |
method: 'POST', | |
headers: myHeader, | |
body: JSON.stringify(fields) | |
}).then(() => { | |
dispatch(contactFormSubmitSuccess()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment