【问题标题】:Force Cache refresh for one container强制刷新一个容器的缓存
【发布时间】:2016-11-25 17:09:24
【问题描述】:

一个简单的例子:

<img id="example" source="example.png"> // This is my container in another file

<scipt>
 // Here I execute a php script that changes the image 'example.png'
 $('#example').hide().load('content/content.php #example').show();
</script>

这个脚本完成后,图片没有更新。

有没有办法强制刷新#example 的缓存。

类似:

 <scipt>
 // Here I execute a php script that changes the image 'example.png'
 $('#example').hide().load('content/content.php #example').show();
 // Refresh Cache for #example or execute php(refresh)
</script>

谢谢

【问题讨论】:

    标签: javascript php jquery html caching


    【解决方案1】:

    如果你请求url,你可以给它添加GET参数,让浏览器认为它在请求一个不同的页面。这使得浏览器始终下载最新版本。

    您可以尝试以下方法。我自己对 JQuery 不是很好,但我相信这会奏效:

    $.get("content/content.php",{},function(e) {
      // now we update the image since the content.php has finished loading.
      $('#example').attr("src","example.png?e="+(new Date().getTime()));
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 2011-08-03
      相关资源
      最近更新 更多