[英]Stop caching of a particular element of a page
Is they any way to stop caching of a particular element in a page, so that it always loads from the server? 他们有什么办法停止页面中特定元素的缓存,以便始终从服务器加载? I have a div element in the page, which contains some session information that needs to be always updated/retrieved from the server.
我在页面中有一个div元素,其中包含一些会话信息,这些信息需要始终从服务器进行更新/检索。
My technology here is PHP/jQuery/Joomla. 我在这里的技术是PHP / jQuery / Joomla。
Does anyone have any idea? 有人有什么主意吗?
When requesting with xmlhttprequest (ajax) one technique could be is to append a time-stamp value to the URL so each time the function is called the request is unique an example could be 当使用xmlhttprequest(ajax)进行请求时,一种技术可能是将时间戳值附加到URL,因此每次调用该函数时,请求都是唯一的,例如
/// javascript get date convert it to milliseconds
function getDateTime(){
return (new Date().getTime());
}
so in your ajax GET for example you could do so each request it appends a new time stamp 因此,例如在您的ajax GET中,您可以这样做,每个请求都附加一个新的时间戳
req.onreadystatechange=function(){
.....
};
req.open("GET",url+"?ac="+t+"&"+ getDateTime() ,true);
req.send("");
Now since you using javascript you would beable to only display the "div's conten" only if js is enabled, thus forcing new content each, so embed a inline script and call a function to populate the div 现在,由于您使用的是JavaScript,因此只有在启用js的情况下,才可以显示“ div的内容”,从而强制每个新内容,因此嵌入一个内联脚本并调用一个函数来填充div
<script>populateDivsContent()</script>
You can stop cache by using following piece of php code: 您可以使用以下php代码停止缓存:
//Set no caching
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.