jason jason - 1 year ago 75
Javascript Question

JSON object reproduces itself

I have this JSON which generates a table :

function show(json)
{
var content = '<table id = "myTable" border = 1>';
var counter;

for(counter = 0; counter < json.length ; counter++)
{
content += '<tr><td class = "topics">' + json[counter]['topic_name'] + '</td>''</tr>';
}
content += '</table>';

$('#table_here').append(content);

}


I call it two times :
1st. here :

$(document).ready(function(){
$.getJSON("admin.php", show);


Second when I add something on the table:

When I add something, the new table appears below the old one, I want to lose the old one and see only the new one. How can I do it?

Answer Source

try to change

$('#table_here').append(content);

into

$('#table_here').html(content);

this will replace the entire content of #table_here element

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