Basic Ajax Cache Issue

Posted by michaelespinosa on Stack Overflow See other posts from Stack Overflow or by michaelespinosa
Published on 2010-12-31T11:19:10Z Indexed on 2010/12/31 11:54 UTC
Read the original article Hit count: 120

Filed under:
|
|
|

I have a single page that I need to on occasion asynchronously check the server to see if the status of the page is current (basically, Live or Offline). You will see I have a function with a var live that is set when the page initially loads. I then do an ajax request to the server to retrieve whether the status of live is true or false. I compare the initial live variable with the newly returned data json object. If they're the same I do nothing, but if there different I apply some css classes. I recursively run it with setTimeout (Is there a better way to recursively do this?).

My Problem: data.live doesn't change from it's initial time it runs even when it has changed in the db. I know my mysql is working because it returs the right value on the initial load. It seems like a caching issue.

Any help is greatly appreciated.

function checkLive() {
    var live = <?=$result["live"]?>;

    $.ajax({
        type: 'get',
        url: '/live/live.php',
        dataType: 'json',

        success: function(data) {
            console.log('checking for updates... current:' + data.live);
            if (data.live == live) {
                return;
            } else {
                var elems = $('div.player_meta, object, h3.offline_message');
                if (data.live == '1') {
                    elems.removeClass('offline').addClass('live');
                } else {
                    elems.addClass('live').addClass('offline');
                }
            }
        }
    });

    setTimeout(function() { checkLive() } ,15000);
} 

checkLive();

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery