1

Below is the code that I am having trouble with -

<script type="text/javascript" language="javascript">

    function loadXMLDoc()
    {
        var xmlhttp;
        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)
        {
            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
        }
        xmlhttp.open("GET","<%=StatsURL%>",true);
        xmlhttp.send();
    }

    function timedRefresh(timeoutPeriod) {
        setTimeout(function(){loadXMLDoc(); autoRefresh();},timeoutPeriod);
    }
    </script>

And this is called in -

<body onload="JavaScript:timedRefresh(50000);">
<div id="myDiv"></div>
</body>

I want to refresh the page/load the XML every 5 seconds however the above code does not appear to work. I have read (http://www.htmlgoodies.com/tutorials/getting_started/article.php/3479551/Reloading-The-Page.htm) that you can use META tags ()to refresh the page as well.

Any help to get this code working would be greatly appreciated.

ANSWER

Change the code to the below -

window.onload = startInterval();

    function startInterval()
    {
        setInterval("loadXMLDoc();", 5000);
    }

1 Answers1

0

That's because you refresh the page every 50 secs (50000 milliseconds). Change it to 5000 and it'll work.

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
  • 1
    Thanks for that input. I actually figured out how to get this done. Instead of calling the timedRefresh within the I changed it to window.onload = startInterval(); function startInterval() { setInterval("loadXMLDoc();", 5000); } – AnonUser224466 Apr 21 '13 at 08:31
  • 1
    @AnonUser224466 great! btw, you might want to read this: http://stackoverflow.com/a/191318/1057429 – Nir Alfasi Apr 21 '13 at 08:35