开发者

Javascript Auto-Refresh Class Elements

开发者 https://www.devze.com 2023-02-14 00:20 出处:网络
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.

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.

Javascript Auto-Refresh Class Elements

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.


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. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消