Refresh Image PHP and Javascript

前端 未结 2 1455
予麋鹿
予麋鹿 2021-01-21 12:50

I am using a Comet, Realtime engine called APE, and I am using jQuery to refresh a PHP image. Initially I load the image like this:

相关标签:
2条回答
  • 2021-01-21 13:07

    A common approach is to add a trivial var to the query string that holds a unix timestamp; The browser sees each call as a call to a unique image. e.g.

    'image.php?device=' + device + '&t=' + Math.round((new Date()).getTime() / 1000);
    

    So that it doesn't think it has a cached image. ( though it will continue whatever cache policy lead to this issue )

    0 讨论(0)
  • 2021-01-21 13:15

    Add an extra random variable onto the image path.

    $("#container").html('<img src="image.php?device='+device+'&rand='+(math.random * 1000000)+'" style="background: url(../assets/load.gif) no-repeat center center;margin-left:42px;" width="500px" height="300px" alt=" Loading ..."/>');
    

    That will make it appear like a different URL and cause the browser not to cache. This is the same tactic used by YUI.

    0 讨论(0)
提交回复
热议问题