Codex73
Codex73

Reputation: 5766

Javascript Auto-Refresh Class Elements

Problem:

Values constantly change on db. Need to auto-reload certain elements values without reloading all page. Very similar to collective bidding pages as attached image.

enter image description here

A simple page Dashboard type with three columns of grid organized data.

How can I effectively reload (AJAX CALL) certain class types, content?

Since these column values change as time goes from db, they have to auto refresh on time interval.

Code Sample:

<div class="autovalue">26</div>
<div class="autovalue">20</div>
<div class="autovalue">96</div>

Maybe Jquery has a method.

Upvotes: 1

Views: 10427

Answers (1)

Guilherme Serrano
Guilherme Serrano

Reputation: 136

Set an interval function, i did this example using jQuery.

var intervalID = setInterval(function(){
   $('.refreshClass').each(function(){
      $(this).load(this.href);
   })
}, 900);

In my example <a href="url-to-get.php" class="refresh"></a> will request the href attribute every 900ms and update the innerHtml.

For a better performance you can cache your selectors and use id instead of classes. :)

Upvotes: 3

Related Questions