0

I have the following script, which is in an external file called at the top of my HTML page. The idea is that I have an Ajax request pinging a database, when the database is updated, the Ajax sees this and calls the function below. It works great in Firefox, but doesn't work at all in IE. Any suggestions?

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);
}

EDIT: In case anyone is curious, I'm using straight javascript for the ajax. Here it is below. I call it on page load, and then it keeps calling itself in a loop.

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();
 }
5
  • 1
    setTimeout(function() { location.reload(true); }, 0); instead of setTimeout("location.reload(true);", 0); Commented Nov 13, 2010 at 17:22
  • Also, terminate the variable statements with semi-colons. Commented Nov 13, 2010 at 17:23
  • I need to see more of your code: how is the XMLHttpRequest instantiated? Commented Nov 13, 2010 at 17:24
  • You're using $.ajax, $.get, $.post, or any of the other jQuery AJAX request functions, right? Commented Nov 13, 2010 at 17:45
  • For the ajax request? No I'm using straight JavaScript Commented Nov 13, 2010 at 17:45

2 Answers 2

2

This isn't an answer but you should replace

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

with

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

As the former is slow and causes extra-evaluation to take place.

EDIT #2: Change GoPopUp() to GoPopUp, you might not want to execute it immediately. Same with checkRefresh.

if (document.getElementById("lastCallID").innerHTML < xmlhttp.responseText)
    {
        setTimeout(GoPopUp, 100); 
    }
    else
    {
        setTimeout(checkRefresh,15000)
    }
Sign up to request clarification or add additional context in comments.

Comments

2

Instead of:

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

you should write:

location.reload(true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.