handle-failed-requests-js
handle-failed-requests-js copied to clipboard
Empty 'data' Object on FormData use
When I try to use formData and the status changes online, the request goes with the empty object "data";
//the eRequests localStorage data
[{method: "post", url: "http://localhost/gibucket/forms/submit_form_data", data: {}}]
0: {method: "post", url: "http://localhost/gibucket/forms/submit_form_data", data: {}}
data: {}
method: "post"
url: "http://localhost/gibucket/forms/submit_form_data"
My javascript code
var data = new FormData();
data.append('form_name', this.form_name);
data.append('form_data', JSON.stringify(form_data));
var req = new Request();
req.send({
method: 'post',
url: route.route,
data: data,
}).then(response => {
console.log(response.data);
}).catch(function (error) {
console.log(error);
});
when online this works perfect so the code is fine. what is not right is that the data object is stored empty in the localstorage
Hey @itsalb3rt,
First of all, sorry about the delay. I actually never tried with FormData, maybe you really found a bug. I will make some tests this week.
Bom dia, estou com o mesmo problema, qual seria a forma correta de informar os dados para o POST ?
Tentei new Object, { } e [ ]
Tudo chega em branco no script PHP !
Hi guys. I just figured out what is the problem. JSON.stringify
really doenst work with FormData
and the library is using this approach, that's why is returing an empty object.
So we need to loop the failed requests array and check if (item instanceof FormData)
, in case of true
, we need to use Object.fromEntries(formData)
and then stringify. It should work as expected.
But unfortunately I got no time to fix it at this moment, just on the next month.
I appreciate if one of you guys could do it.
I just wrote some code that should fix this problem, if you guys could help testing and sending a feedback...