Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty 'data' Object on FormData use #4

Closed
itsalb3rt opened this issue Jan 30, 2019 · 4 comments · May be fixed by #5
Closed

Empty 'data' Object on FormData use #4

itsalb3rt opened this issue Jan 30, 2019 · 4 comments · May be fixed by #5

Comments

@itsalb3rt
Copy link

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

@arojunior
Copy link
Owner

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.

@marciotisouza
Copy link

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 !

@arojunior
Copy link
Owner

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 added a commit that referenced this issue Oct 26, 2019
Add support when data type is FormData

closes #4
@arojunior
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants