2010-11-13 133 views
0

我有以下腳本,它位於我的HTML頁面頂部調用的外部文件中。這個想法是,我有一個Ajax請求ping數據庫,當數據庫更新時,Ajax會看到並調用下面的函數。它在Firefox中很好用,但在IE中完全不起作用。有什麼建議麼?jQuery腳本不能在IE中工作?

var GoPopUp = function(){ 
    $('#PopNewCall').fadeIn('slow'); 
    PageRefreshTimer(); 
} 

//Function which refreshes page after a certain number of seconds with no user Inputs 
var PageRefreshTimer = function(){ 
    setTimeout("location.reload(true);",30000); //1,000 = 1 second 
} 

//Function which refreshes page after user has clicked refresh 
var RefreshNow = function(){ 
    setTimeout("location.reload(true);",0); 
} 

編輯:如果任何人都好奇,我使用直的JavaScript的Ajax。下面是它。我在頁面加載時調用它,然後它一直在循環中調用它自己。

function checkRefresh(str) 
{ 
if (window.XMLHttpRequest) 
{// code for IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp=new XMLHttpRequest(); 
} 
else 
{// code for IE6, IE5 
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttp.onreadystatechange=function() 
{ 
if (xmlhttp.readyState==4 && xmlhttp.status==200) 
{ 
    if (document.getElementById("lastCallID").innerHTML < xmlhttp.responseText) 
    { 
     setTimeout(GoPopUp(), 100); 
    } 
    else 
    { 
     setTimeout('checkRefresh()',15000) 
    } 

    } 
} 
xmlhttp.open("GET","getnewid.php",true); 
xmlhttp.send(); 
} 
+1

'的setTimeout(函數(){location.reload(真);},0);',而不是' setTimeout(「location.reload(true);」,0);' – 2010-11-13 17:22:33

+0

另外,用分號終止變量語句。 – 2010-11-13 17:23:49

+0

我需要看到更多的代碼:'XMLHttpRequest'如何實例化? – 2010-11-13 17:24:34

回答

2

這不是一個答案,但你應該

setTimeout(function(){ location.reload(true) }, 0); 

更換

 setTimeout("location.reload(true);",0); 

由於前者是緩慢而造成額外的評估發生。

編輯#2:將GoPopUp()更改爲GoPopUp,您可能不想立即執行它。與checkRefresh相同。

if (document.getElementById("lastCallID").innerHTML < xmlhttp.responseText) 
    { 
     setTimeout(GoPopUp, 100); 
    } 
    else 
    { 
     setTimeout(checkRefresh,15000) 
    } 
2

相反的:

setTimeout(function(){ location.reload(true) }, 0); 

你應該寫:

location.reload(true);