문제

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

도움이 되었습니까?

해결책

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.

다른 팁

  • 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top