Bhagyashree
Bhagyashree

Reputation: 21

Update json data without refreshing the page?

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

Answers (3)

Yaniv Efraim
Yaniv Efraim

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

Denys Séguret
Denys Séguret

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

Manse
Manse

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

Related Questions