D
D
DarthJS2017-02-08 17:45:38
JavaScript
DarthJS, 2017-02-08 17:45:38

How to organize the formdata object so that it looks like this?

There is an error when sending FormData POST data using the method.
Data should be transmitted in the following way:
Headers
Form Data:

LoginForm[email]:234
LoginForm[password]:234
LoginForm[rememberMe]:0
LoginForm[rememberMe]:1

My code:
function submit(form){
     var formData = new FormData();
            formData.append('LoginForm[email]', form.email);
            formData.append('LoginForm[password]', form.password);
  // OR
   formData.append('LoginForm',  form)
}

When submitting to Headers:
Headers
Form Data:
------WebKitFormBoundaryraUeNL6VjAnyGIUh
Content-Disposition: form-data; name:"LoginForm[email]"

[email protected]
------WebKitFormBoundaryraUeNL6VjAnyGIUh
Content-Disposition: form-data; name="LoginForm[password]"

123456
------WebKitFormBoundaryraUeNL6VjAnyGIUh--

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-02-08
@emp1re

obj['a'] === obj.a // true
if angular, pass data to the controller/component, then work with the server api through the service, I don't think it's good to send data directly from the form. And accordingly, in the controller, work with the type of your data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question