Reputation: 21
I have a list of users which comes from JSON data. After a certain time interval I want to display the list of users have to be updated and if any new entries are found in the JSON data and also if any entry get deleted from JSON data.
I am using the setInterval()
function, but the list of users get blinked all the times which I dont want to show (effect of blinking the all data).
Initially I used $("#test").html(" ");
and then an AJAX call.
Does anybody have the idea for this problem?
Upvotes: 2
Views: 1676
Reputation: 6713
You can use the kcnockout.js library which has data binding with JavaScript objects and observable behaviour. It is exactly what you are looking for. (it will update the changed data automatically)
Upvotes: 0
Reputation: 382112
Why do you empty the list before your ajax call ?
If you simply completely rebuild your new html (say newListHtml) from the json data you received with your ajax call and then do
$("#test").html(newListHtml);
there will be no blinking.
Upvotes: 0
Reputation: 38147
You can use .append() to append text to a DOM element eg
<div id="list">some text</div>
$('#list').append(' some more text');
creates a div
with some text some more text
inside
Example using setInterval
and append
Upvotes: 4