如何使用javascript或php禁用Internet Explorer缓存 [英] How to disable internet explorer cache using javascript or php

查看:62
本文介绍了如何使用javascript或php禁用Internet Explorer缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an php powered application with javascript and many jax calls. my application is working upto date in firefox. but when i run it in internet explorer-8 or similar versions my ajax call gets cached in my browser so i am not able to output the upto date info with the ajax calls instead the result for that ajax calls are served with old data's which reside in the browser cache.

 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代码

2.)I added Following php code

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');

但上述2种方法仍无法解决我的问题,即请任何人帮助我禁用缓存我的应用程序运行时的Internet Explorer,以便可以获取最新信息。

But still the above 2 approaches did not solve my problem ie, please can anybody help me to disable caching internet explorer when my application runs, so that its possible to get upto date information.

提前感谢

推荐答案

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

Make each AJAX request unique in some way. That will prevent IE from caching the response.

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

For example, if your normal AJAX query URL is www.mysite.com/ajax.php?dog=cat, add in a querystring parameter to each AJAX request that is unique:

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

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

每次发出AJAX请求时都会增加该参数,这应该可以帮到你。

Increment that parameter each time you make an AJAX request, and that should hopefully do the trick for you.

这篇关于如何使用javascript或php禁用Internet Explorer缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆