Basic Ajax Cache Issue

前端 未结 3 1035
感情败类
感情败类 2020-12-07 06:48

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

3条回答
  •  [愿得一人]
    2020-12-07 07:13

    Use the cache option of $.ajax() to append a cache breaker to the URL, like this:

    $.ajax({
        type: 'get',
        url: '/live/live.php',
        dataType: 'json',
        cache: false,
        //success, etc.
    });
    

    If that doesn't resolve it...look at firebug, see if a request is being made (it should be after this for sure), if it's still getting an old value, the issue is in PHP, not JavaScript.


    Unrelated to the issue, just a side tip: If you need no parameters, you can skip the anonymous function call, this:

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

    can just be:

    setTimeout(checkLive, 15000);
    

提交回复
热议问题