Answer the question
In order to leave comments, you need to log in
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
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
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?
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...
jQuery has a function specifically for collecting all fields, api.jquery.com/serialize/.var postData = $("form").serialize();
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 questionAsk a Question
731 491 924 answers to any question