i wonder how do websites update time dynamically without ajax requests ? what i have is a comment system .
$('#comment').click(function(){
$.post(url,{
comment : $(this).siblings('textarea.#comment_content').val();
},function(data){
$('#comments').append(data.output);
},'json');
});
PHP
<?php
//get comment and update into DB
$output .= '<div class="comment-text">'.$comment_text.'</div>'; //comment entered right now
$output .='<div class="showTime">'.getTime(time()).'</div>';
/*
getTime() is a function where time is entered and calculated according to current "time()" and formatted in words
*/
?>
since now the comment is appended how will i change the content inside .showTime
without ajax requests ?
UPDATE
I am sending a php time() to javascript for processing but its showing Invalid Date here's whats happening
<div class="tstamp" time="<?php echo strtotime($row['time']) ?>" ></div> //time from database
When i am recieving this via js it shows Invalid Date
var $time = new Date($('.tstamp').attr('time'));
console.log($time); //console shows error
i also tried these formats but same problem...
D M d Y H:i:s O
d/m/Y H:i:s
d/m/Y H:i:s A
UPDATE
multiplied the strtotime
with 1000