javascript IE 和 setInterval() 不刷新/更新的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3426510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problem with IE and setInterval() not refreshing/updating
提问by Joey Morani
I'm using JavaScript/Jquery to make a page auto-update with a value from a database, although it doesn't seem to update in Internet Explorer. It works fine in FireFox & Chrome. Can anyone explain what's wrong? It looks like IE is just displaying a cached version of the page. How can I prevent this happening? Thanks.
我正在使用 JavaScript/Jquery 使用数据库中的值使页面自动更新,尽管它似乎没有在 Internet Explorer 中更新。它在 FireFox 和 Chrome 中运行良好。谁能解释一下出了什么问题?看起来 IE 只是显示页面的缓存版本。我怎样才能防止这种情况发生?谢谢。
function updateComm() {
var url="commandSys.php";
jQuery("#theElement").load(url);
}
setInterval("updateComm()", 1000);
回答by meder omuraliev
Try disabling the cache with ajaxSetup
尝试禁用缓存 ajaxSetup
$.ajaxSetup ({
// Disable caching of AJAX responses */
cache: false
});
function updateComm() {
var url="commandSys.php";
jQuery("#theElement").load(url);
}
setInterval(updateComm, 1000);
Alternatively, you can manually just append a +new Dateto urlso it appends a query string to prevent caching.
或者,您可以手动仅附加一个+new Datetourl以便附加查询字符串以防止缓存。
Alternatively, disable caching on the server-side.
或者,禁用服务器端的缓存。
回答by epascarello
Your php page is cached. Has nothing to do with the interval. Set the right caching headers on the page.
您的 php 页面已缓存。与间隔无关。在页面上设置正确的缓存标头。

