I have a simple HTML form and I'm sending some data to my server by using Fetch API and FormData.
I'm sending role
and user_id
with their values to the server. In controller when I print params
I get:
{"-----------------------------1190833731009709688837505639\r\nContent-Disposition: form-data; name"=>"\"role\"\r\n\r\nadmin\r\n-----------------------------1190833731009709688837505639\r\nContent-Disposition: form-data; name=\"user_id\"\r\n\r\n1\r\n-----------------------------1190833731009709688837505639--\r\n", "controller"=>"users", "action"=>"updaterole", "id"=>"1"}
How can I access and get role
and user_id
value from this?
This is my script on client side:
var form = document.querySelector("#roleForm");
var formdata = new FormData(form);
fetch(url, {
method: "PATCH",
headers: { 'Content-Type':'multipart/form-data' },
body: formdata,
}).then(
response => response.text() // .json(), etc.
// same as function(response) {return response.text();}
).then(
html => {
console.log(html)
}
);
in my case, that it is alredy mentioned in comments, we have incorrect body.
i solved it by removing headers: { 'Content-Type':'multipart/form-data' },
form fetch request.. looks like we dont need add Content-Type to header. anyway my issue solved by this .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With