如何使用javascript或php禁用Internet Explorer缓存

gow*_*mar 6 javascript php internet-explorer

我有一个PHP驱动的应用程序与JavaScript和许多jax调用.我的应用程序在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'>
Run Code Online (Sandbox Code Playgroud)

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');
Run Code Online (Sandbox Code Playgroud)

但仍然上面的两种方法没有解决我的问题,即,任何人都可以帮助我在我的应用程序运行时禁用缓存Internet Explorer,以便可以获取最新信息.

提前致谢

Jam*_*mes 9

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

例如,如果您的普通AJAX查询URL是www.mysite.com/ajax.php?dog=cat,请为每个唯一的AJAX请求添加一个查询字符串参数:

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

每次发出AJAX请求时都会增加该参数,这应该有希望为您完成.