2010-11-13 134 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);