如何使用javascript或php禁用ie缓存


How to disable internet explorer cache using javascript or php

我有一个php驱动的应用程序,其中包含javascript和许多ajax调用。我的应用程序在firefox中是最新的。但是,当我在Internet explorer-8或类似版本中运行它时,我的ajax调用会缓存在浏览器中,因此我无法用ajax调用输出最新的信息,而不是ajax调用的结果与驻留在浏览器缓存中的旧数据一起服务。

 I have tried lots of possible options as listed below
1.) I added following meta tag in header files

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

2)。我添加了以下php代码

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');

但是以上两种方法仍然没有解决我的问题,即,请任何人帮助我禁用缓存internet explorer当我的应用程序运行时,以便有可能获得最新的信息。

thanks in advance

以某种方式使每个AJAX请求唯一。这将阻止IE缓存响应。

例如,如果您的普通AJAX查询URL是www.mysite.com/ajax.php?dog=cat,那么在每个AJAX请求中添加一个惟一的querystring参数:

www.mysite.com/ajax.php ?狗= cat& queryid = 1

在每次发出AJAX请求时增加该参数,这应该能够满足您的要求。