1

    function Save() {
           var count = $("#count").val();//count to iterate
           var obj = {}
           for (var i = 0; i < count ; i++)  //iterating for each set of id's
           {
               obj = {
               chckaids : $("#chckaids" + i).val(),
               size : $("#size " + i).val(),
               freq : $("#freq" + i).val(),
               control : $("#control " + i).val(),
               plan : $("#plan" + i).val(),
               type : $("#type").val(),
               qty : $("#qty").val(),
               rejected : $("#rejected ").val(),
               remark : $("#remark").val()
               }
           }

    $.ajax({
                   url: "../SaveQCInspection",
                   type: "Post",
                   data: JSON.stringify([obj]),                                                                                                                                                          
                   contentType: 'application/json; charset=utf-8',                                                                                                                                                                                                                                                                                           
                   success: function (data) {                                                                                                                                                                                                                                                                                                               
                    },
                   error: function () { }
               });
       }

I need to get all the values in the dynamic id's and pass it to ajax as single object...Experts told me to use Json-model,I googled but still didn't get any idea about that.....Please guide me whether it is easy to use json model or it is the only way to acheive this ...

Thank you in advance.....:)

  • 1
    Why are you using `id` attributes? Just use class names and relative selectors. But the main issue is you need to create an array, and push the objects into the array –  Aug 08 '18 at 11:31
  • Yeah,but can be it done using json model classes – M.Hariharan Aug 08 '18 at 11:51
  • What do you mean _using json model classes_? –  Aug 08 '18 at 11:52
  • It means a model for to and get data...Like the way in mvc....I also heard about json model today only and still researching...If anybody aware of that and incase my statement is false...Kindly share your knowledge – M.Hariharan Aug 08 '18 at 11:58

1 Answers1

1

You can push your items to an array then can stringify it

function Save() {
           var count = $("#count").val();//count to iterate
           var list = [];

           for (var i = 0; i < count ; i++)  //iterating for each set of id's
           {
               var obj = {
               chckaids : $("#chckaids" + i).val(),
               size : $("#size " + i).val(),
               freq : $("#freq" + i).val(),
               control : $("#control " + i).val(),
               plan : $("#plan" + i).val(),
               type : $("#type").val(),
               qty : $("#qty").val(),
               rejected : $("#rejected ").val(),
               remark : $("#remark").val()
               }

               list.push(obj)
           }

    $.ajax({
                   url: "../SaveQCInspection",
                   type: "Post",
                   data: JSON.stringify(list),                                                                                                                                                          
                   contentType: 'application/json; charset=utf-8',                                                                                                                                                                                                                                                                                           
                   success: function (data) {                                                                                                                                                                                                                                                                                                               
                    },
                   error: function () { }
               });
       }
mehmetx
  • 850
  • 6
  • 6