How do I keep webpage REFRESHED

Topics: Developer Forum
Aug 8, 2013 at 4:52 AM
how do I refresh the page -- every 30 seconds automatically?
Aug 8, 2013 at 10:47 AM
Refresh you be triggered by the browser.

I was curious about that myself, but it looks like a simple HTML Header attribute:

<meta http-equiv="refresh" content="30">

http://www.w3schools.com/tags/att_meta_http_equiv.asp
Coordinator
Aug 8, 2013 at 6:33 PM
Edited Aug 8, 2013 at 6:35 PM
Well this is what AJAX is all about:

http://stackoverflow.com/questions/10861407/how-to-automatically-refresh-data-on-page-using-ajax-on-an-interval

simply ask for a file from the server and it updates a div on the client every 5 seconds with the content of the file (jQuery would make this even easier probably):
<div id="content">
  <script>
    var f;
    function buildContent(xml)
    {
        f = xml;
        //Build the new child andd append it to the father
        el =  document.getElementById("content");
        // var txtNode = document.createTextNode(txt);
        // el.appendChild(txtNode);

        ulElement = document.createElement("ul");
        for (var i = 0; i < f.length; i++)
        {
            li = document.createElement("li")
            a = document.createElement("a")
            a.setAttribute("onclick", 'buildBar('+ i + ')');

            var txtNode = document.createTextNode(f[i].getElementsByTagName("bar")[0].childNodes[0].nodeValue);
            a.appendChild(txtNode);
            li.appendChild(a);
            // document.write("</li>");
            ulElement.appendChild(li);
        }
        el.appendChild(ulElement);
    }

    function buildBar( i)
    {

        qux = (f[i].getElementsByTagName("qux")[0].childNodes[0].nodeValue);
        document.getElementById("displayBar").innerHTML = qux;
    }
  </script>
</div>

<div id="displayBar">
  </div>

  <script>
    function doItOnInterval()
    {
        //Perform the Ajax request
        window.XMLHttpRequest
        {
            xmlhttp = new XMLHttpRequest();
        }
        xmlhttp.open("GET", "data.xml", false);
        xmlhttp.send();

        loadXMLDoc = xmlhttp.responseXML;
        f = loadXMLDoc.getElementsByTagName("foo");

        //Remove all child of the div
        el =  document.getElementById("content");
        if ( el.hasChildNodes() )
        {
            while ( el.childNodes.length >= 1 )
            {
                el.removeChild( el.firstChild );       
            } 
        }

        //Send the text to rebuild the content
        buildContent(f);
    }

    //Call the ajax refresh each 5 seconds
    doItOnInterval();
    setInterval("doItOnInterval()", 5000);
  </script>