Refresh Div with Jquery at fixed time

Posted by Ben C on Stack Overflow See other posts from Stack Overflow or by Ben C
Published on 2010-03-30T16:28:15Z Indexed on 2010/03/30 16:33 UTC
Read the original article Hit count: 182

Filed under:
|
|
|

I've got a php script that tells me when the next bus is due, and at the moment I'm refreshing this into a div, using jquery, every minute or so. Now, because I know the time at which the data will change (after the bus has come), I want it to refresh the div at this time (or just after, doesn't really matter).

I should point out that I'm fairly new to js, but this is what I've got so far:

    var nextbustime = $('#bus').contents();
var nextbustime = new Date(nextbustime);
var now = new Date();

var t = nextbustime.getTime() - now.getTime();


var refreshId = setTimeout(function()
{
    $('#bus').fadeOut("slow").load('modules/bus.php?randval='+ Math.random()).fadeIn("slow");
}, t);

The div is loaded originally with a php include. Naturally, what I've done doesn't work at all.

Do I need some loops going on? Do I need to refresh the time calculator?

Please please help!

Thanks in advance...

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery