handle-failed-requests-js icon indicating copy to clipboard operation
handle-failed-requests-js copied to clipboard

Empty 'data' Object on FormData use

Open itsalb3rt opened this issue 6 years ago • 4 comments

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

itsalb3rt avatar Jan 30 '19 01:01 itsalb3rt

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.

arojunior avatar Feb 04 '19 11:02 arojunior

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 !

marciotisouza avatar Oct 21 '19 12:10 marciotisouza

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.

arojunior avatar Oct 25 '19 17:10 arojunior

I just wrote some code that should fix this problem, if you guys could help testing and sending a feedback...

arojunior avatar Oct 26 '19 02:10 arojunior