缓存内容
问题描述:
我正在为项目制作一个门户页面,并且每1000秒刷新一次包含的div。缓存内容
虽然我遇到的问题是被拉入的内容总是被缓存,所以刷新没有效果,用户必须进行硬刷新。
这只发生在Internet Explorer
这是我用来刷新并加载DIV的JavaScript代码:
var auto_refresh = setInterval(
function() {
$('#news').load('apps/news.php').fadeIn("slow");
}, 1000);
正如你所看到的,数据包含在PHP文件。 news.php的
内容:
<dl class="news">
<dt>09/01/08</dt>
<dd>
<a href="#"><img src="/images/news1.jpg" alt="News image 1" /></a>
<p><a href="#">Opal network services resume - Bada Bing!</a></p>
</dd>
<dt>07/01/08</dt>
<dd>
<a href="#"><img src="/images/news3.jpg" alt="News image 3" /></a>
<p><a href="#">Anglia Contemporary Theatre - "Some news-pschitt!"</a></p>
</dd>
<dt>07/01/08</dt>
<dd>
<a href="#"><img src="/images/news4.jpg" alt="News image 4" /></a>
<p><a href="#">ALSS Faculty Research Seminar - Novel Plots: Narrative in Nineteenth-Century Verbal and Visual Fictions</a></p>
</dd>
</dl>
我怎么去设置它,这样的数据不被缓存?
感谢
答
当前时间添加到查询的URL的末尾:
var auto_refresh = setInterval(
function() {
$('#news').load('apps/news.php?random='+(new Date()).getTime()).fadeIn("slow");
}, 1000);
答
添加无缓存成news.php的缓存指令或有短暂缓存“说500秒'以提高< 1000s刷新的性能。根据您的需要调整缓存策略。从http://www.php.net/manual/en/function.header.php
样品:
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
这是伟大的,我认为这是不可能的。 – bear 2009-08-11 15:32:32