我編寫了一個簡單的代碼來從PHP文件獲取內容並每隔30秒刷新一次。 它在FireFox上很漂亮,但在IE8中只加載一次內容! 可以任何身體幫助我解決它?!Jquery setInterval在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();
具有相同代碼的重複副本是壞的。您應該將通用代碼放在一個函數中,並將其調用兩次,而不是複製/粘貼相同的代碼。 – jfriend00 2012-02-19 03:13:27