【发布时间】:2012-02-19 02:24:04
【问题描述】:
我编写了一个简单的代码来从 PHP 文件中获取内容并每 30 秒刷新一次。 它在 FireFox 上运行良好,但在 IE8 中只加载一次内容! 任何人都可以帮我解决它吗?!
这是我的代码:
<script>
var content;
var temp = "something";
$.get('refresh.php', function(data) {
content = data;
})
.success(function() {
if (temp != content) {
$("#success").fadeOut(2000, function ()
{
$("#success").html(content).fadeIn(2000);
}
); // end .fadeOut
temp = content;
}
}) //end .success
.error(function() { $("#success").html("error"); });
var refreshId = setInterval(function()
{
$.get('refresh.php', function(data) {
content = data;
})
.success(function() {
if (temp != content) {
$("#success").fadeOut(2000, function ()
{
$("#success").html(content).fadeIn(2000);
}
); // end .fadeOut
temp = content;
}
}) //end .success
.error(function() { $("#success").html("error"); })
}, 27000);
</script>
在 PHP 代码上我有这个代码:
echo rand();
【问题讨论】:
-
拥有相同代码的重复副本是不好的。您应该将通用代码放在一个函数中并调用它两次,而不是复制/粘贴相同的代码。
标签: jquery firefox internet-explorer-8 setinterval