I have written a React-component which should be used for all forms in my application. When a certain button is clicked I make some validation and finally I want to post the form to the server. This is what this part currently looks like:
// get what should be submitted
const formData = new FormData(theForm)); // theForm is the DOM-element
// post the form-data element
fetch(theForm.action,
{
credentials: "include", //pass cookies, for authentication
method: theForm.method,
headers: {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
//"Content-Type": "application/x-www-form-urlencoded"
},
body: formData
})
.then(res => console.dir(res))
.catch(reason => console.error(reason));
The shown snippet work fine in Chrome
. However, in IE11
it is not.
On the other hand, when uncommenting the Content-Type
header, it will also break in Chrome
.
As found https://stackoverflow.com/a/46642899/615288 it is always "multipart/form-data"
. But even if I set it to multipart/form-data
the values are not send to the server.
I am using the FormData polyfill from https://github.com/jimmywarting/FormData as well as whatwg-fetch
.
I don't see what is going on here as FormData should work in IE since version 9.
Sidenote: When commenting out the whole header-part it still works in Chrome
as the browser seems to guess the correct ones (as it can be seen in the developer-tools)