-1

The setInterval function does not work on I.E. 10. I have a web page that when a form is submitted, it will trigger a long process on the server for downloading a file. I use setInterval to repeatly poll the server for progress so that the user gets some kind of update on the progress.

The ProgressServlet will only get called once only. I did not test this on another web browser because it is "illegal" to use another browser in my company.

<script>

var myVar;

function validateForm()
{
 //validation logic omitted
        myVar = setInterval(getProgress(), 1000);
 return true; 
}   


function getProgress() {
 //ProgressServelt will return progress of the long process on the server
 $.get("ProgressServlet", $.now(), function(res) {
  if (res != "9999" || res == "No value avaliable")  {
   $("#progress").html(res);

  } else {
   $("#progress").html("Stopped: " + res);
   clearInterval(myVar);
  }
 });
  
}

</script>
<form method="post" action="CreateServlet" name = "create">

Change Number(s):<br>
<input type="text" name="change" id="change">
<p></p>
<input type="submit" value="Download" onClick="return validateForm()">

</form>
<p></p>
<button  id="send" name="send">Display</button>
Meelo dog
  • 13
  • 4
  • get caches so hopefully you set the correct no cache headers – epascarello May 19 '15 at 18:34
  • Duplicate of [Why is my function call that should be scheduled by setTimeout executed immediately?](http://stackoverflow.com/questions/2037203/why-is-my-function-call-that-should-be-scheduled-by-settimeout-executed-immediat) – apsillers May 19 '15 at 18:37

1 Answers1

3

Change

myVar = setInterval(getProgress(), 1000);

to

myVar = setInterval(getProgress, 1000);

That is: pass the function, not what it returns.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758