serializing a jquery template form into json using jquery

545 views Asked by At

I have a form for which I use JQUERY templates, as there can be multiple fields for an attribute. For eg. a user can have multiple phone numbers. So, he can add fields dynamically by pressing the option "add one more number". In this way multiple fields are added but all have the same name.
How should I serialize this kind of form data into a JSON object?
--Thanks in advance

2

There are 2 answers

4
Jason On BEST ANSWER

You can serialize a form with $(form).serialize ()

I'm not sure what the element id has to do with anything, but they should be unique on a page.

2
Yogesh On
  • You can set name attribute for multiple fields to consider it as array. Example is below <input type="text" name="phone[]"> <input type="text" name="phone[]"> <input type="text" name="phone[]">

  • Now for submitting you can use serializeArray() function to post the data to serverside script

I hope this will work for you