I want to make the time of each post to change in realTime.
This is only the font with the time,beacuse this is want is the important here.
<font class="timestamp" postdate="unixTimeStamp" postID="6">2 min ago</font>
<font class="timestamp" postdate="unixTimeStamp" postID="5">4 min ago</font>
<font class="timestamp" postdate="unixTimeStamp" postID="4">9 min ago</font>
An this is the javascript
setInterval(updateTimestamps,30000);
var realTime=<?php echo time();?>;
function updateTimestamps(){
$(".timestamp").each(function(i){
var timestamp=$(this).attr("postdate"),
postID=$(this).attr("postID"),
math=realTime-timestamp;
if(math<3600){var dataString='postID='+postID+'×tamp='+timestamp;
$.ajax({
type:"POST",
url:"http://site.com/ajax/humanTime.php",
data:dataString,
cache:false,
success:function(html){
$("[postID='"+postID+"']").html(html);
}
});
}
});
}
In humanTime.php I calculate the time:
$timestamp = $_POST['timestamp'];
$now=time(); $diff= $now - $timestamp; and so on..
But the problem is that it makes to many connections,beacuse the script is called for every post. And thought that maybe i can make 1 connection sort the data into a array and then to change the time. But i never worked with json and i'm sure if what i want is really possible
Mathis an existing JavaScript object (and a reserved keyword), it's confusing to create a variable namedmath. Name your variables after what they actually represent to make your code easier to re-read.