Jump to content

update a number of divs at a certain Interval (partially working)


shortysbest

Recommended Posts

I am trying to automatically update the time of comments (much like facebook says "just a moment ago, a few seconds ago, 15 minutes ago, etc.)

 

I have it working as far as updating one of the comments' dates, but cannot get it to update each one all the way down through them.

example:

 

Comment 1 Date  <---this one updates, but none of them below do

Comment 2 Date

Comment 3 Date

Comment 4 Date

 

my html for the div of the id is:

 

<div id="<?php print $id?>" class="comment-date"><?php print time_stamp($date)?></div>

 

(id is the unique id of the comment)

 

 

$(document).ready(function(){
					   
setInterval(function() {
											  
var id = $(".comment-date").attr("id");

$.ajax({
type: "POST",
url: "ajaxpages/php/update_date.php",
data: "comment_id="+id,
cache: false,
success: function(html){

$("#"+id+" .comment-date").html(html);
}
});	

}, 100);});

$(document).ready(function(){
  setInterval(function() {
    $(".comment-date").each(function() {
      var $element = $(this);
      var id = $element.attr('id');
      $.ajax({
        type: "POST",
        url: "ajaxpages/php/update_date.php",
        data: {comment_id: id},
        cache: false,
        success: function(html) {
          $element.html(html);
        }
      });
    });
  }, 100);
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.