Jump to content

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


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);
});

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.