Skip to content

Instantly share code, notes, and snippets.

@yushanwebdev
Last active September 28, 2021 05:15
Show Gist options
  • Save yushanwebdev/dcab9c3da5dd8894ac2efc7df8e71207 to your computer and use it in GitHub Desktop.
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()`
// 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