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