Metio_1993 Metio_1993 - 1 year ago 127
HTML Question

How to update a table from Ajax post callback Symfony 3

I have a table that needs to be updated by Ajax callback, I'm really struggling to find the right way to do so.

here is a picture how the table should look like:
enter image description here

I cannot find the right way to so, here is my current HTML script:

<table class="table table-striped">
<th>Object Description</th>

<th scope="row"><input id="ID"></th>
<td><input id="NC"></td>
<td><input id="Des"></td>


And here is the callbacks from Ajax:

} ,
function (data)
obj1 = data[0];
obj2 = data[1];

var obj = JSON.parse(obj2);
var obj1 = JSON.parse(obj1);


can someone please tell me if I'm doing it right and how I can send all the values from because now I can send only value 1 from the array.

Answer Source

you need a success function in ajax. easier option would be to echo the value from the php page where ajax response is sent. such as

echo '<tr>
        <td scope="row">' . $idValue . '</th>
        <td>' . $12ncValue . '</td>
        <td>' . $descriptionValue . '</td>

and in the success function you can append to the tbody after you give it a class or id.

<tbody id="tbody">

success: function (response) {

as for another approach would be declare an array of variables, and

echo json_encode($array)

and with .each function you can loop the data from the ajax success function.

Edit: if you get the value. you need to append them. give id to tbody

</tbody id="tbody">

and in function(data)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download