K
K
KOPC18862014-11-24 17:14:16
JavaScript
KOPC1886, 2014-11-24 17:14:16

How to create a form so that when submitting it with ajax, collect all the fields?

Hello!

How to create a form that has file type fields (so that you can add many files), as well as multiple type fields, for example, several categories, and so on.

And to simply send this form with Ajax and then collect all the fields on the server side?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexander Miranovich, 2014-11-24
@aleks_664

First, check if input type=file has changed, if it has changed, add another input type=file, set all fields to name, and then read how to submit the form with ajax

K
KOPC1886, 2014-11-24
@KOPC1886

Is it better to create a form and add a name to the fields, or is it better without a form, and then collect the necessary id into arrays ourselves and send an Ajax request? how to do it better? I thought it would be easier to make such a complex form through angular? Or is it better to do it manually with jquery?

S
Sergey Gladkovskiy, 2014-11-24
@SMGladkovskiy

Make a normal form and process it with a plugin like https://github.com/malsup/form/. You will have a normal form submission, only ajax...

R
Rafael Hovhannisyan, 2014-11-24
@hosembafer

jQuery has a function specifically for collecting all fields, api.jquery.com/serialize/.
var postData = $("form").serialize();

S
Sergey Romanov, 2014-11-25
@Serhioromano

In Angular, in the controller, declare a variable.
And in templates, bind everything to this variable. For example.
Thus, you will have all the data in $scope.form. Just pass it to $http when you make a request to the server and everything that is on the form will be there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question