Pregunta

I have an html page that updates a graph every 20 seconds with data from a database. I call this function to set a delay before querying the database again:

setTimeout(update, 20000);

This calls the function update:

function update() {
    $.get('getRealtimeData.php?', function(data) {
        //data is parsed and sent to the graph successfully.
    }
}

Which calls the php page with this code:

//parameter retrieval and connection
$query = "select KiloBytesTransferred, DateTimeInitiated from Flows where DateTimeInitiated > date_add(now(), interval ? hour)";

$hours = -1; //normally populated by parameter sent to the page 

$stmt = $con -> stmt_init();

$persecond = 0;

if ($stmt -> prepare($query)) {
    $stmt -> bind_param('d', $hours);
    $stmt -> execute();
    $stmt -> bind_result($KiloBytesTransferred, $DateTimeInitiated);
    while ($stmt -> fetch()) {
        $persecond = $KiloBytesTransferred / 60;
        echo $persecond;
        echo ",";
        echo $DateTimeInitiated;
        echo ";";
    }
    $stmt -> close();
}
$con -> close();

When I debug this project in Firefox or Chrome and set an alert with the results from the database, it works fine. When I try to run this project in Internet Explorer, the data doesn't change. Each time the database is queried, the results back are the same. I verify this by checking the DateTimeInitiated column. Even minutes later the query returns data as though the 'now()' part of the query hasn't changed.

I have tried substituting now() with sysdate(), and achieve the same results. Running the same project on other computers (my teammates') produces the same results as well. Refreshing the page produces new data, but the subsequent calls don't change as before.

I am trying to get the data to change with subsequent calls in Internet Explorer as that will be the main browser that will be used to access the page. I've tried researching, but haven't found anything where the sysdate/now doesn't change on completely different calls. I am a beginner in both PHP and JavaScript, and this is for a project for a real client in our Capstone class, so any suggestions are welcome.

¿Fue útil?

Solución

Try adding a random parameter to the URL, to prevent it from caching eg:-

function update() {
    var rndNum = Math.round(new Date().getTime() / 1000);
    $.get('getRealtimeData.php?rand='+rndNum, function(data) 
    {
        //data is parsed and sent to the graph successfully
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top