javascript - How to update a table from Ajax post callback Symfony 3 -


i have table needs updated ajax callback, i'm struggling find right way so.

here picture how table should like:

enter image description here

i cannot find right way so, here current html script:

    <table class="table table-striped"> <thead> <tr>     <th>#</th>     <th>12nc</th>     <th>object description</th>  </tr> </thead> <tbody>     <tr>         <th scope="row"><input id="id"></th>         <td><input id="nc"></td>         <td><input id="des"></td>     </tr>  </tbody> 

and here callbacks ajax:

                        person_name:$('#input_text').val()                      } ,                      function (data)                      {                          obj1 = data[0];                          obj2 = data[1];                            var obj =  json.parse(obj2);                           var obj1 =  json.parse(obj1);                             $('#id').val(obj1[1].id);                          $('#nc').val(obj1[1].n_c);                          $('#des').val(obj[1].description);                      }                  );              })             }         ); 

can please tell me if i'm doing right , how can send values because can send value 1 array.

you need success function in ajax. easier option echo value php page ajax response sent. such

echo '<tr>         <td scope="row">' . $idvalue . '</th>         <td>' . $12ncvalue . '</td>         <td>' . $descriptionvalue . '</td>       </tr>'; 

and in success function can append tbody after give class or id.

<tbody id="tbody">   success: function (response) {                     $('#tbody').append(response);                    } 

as approach declare array of variables, ,

echo json_encode($array) 

and .each function can loop data ajax success function.

edit: if value. need append them. give id tbody

</tbody id="tbody"> 

and in function(data)

 $('#tbody').append('<tr><td>'+obj1[1].id+'</td><td>'+obj1[1].n_c+'</td><td>'+obj[1].description+'</td></tr>'); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -