Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6721393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:19:31+00:00 2026-05-26T09:19:31+00:00

I need to refresh a php script every ten seconds, it is for a

  • 0

I need to refresh a php script every ten seconds, it is for a update system, It looks for any new updates and then returns a value to javascript/php and then in displays them to the user in a div?

Is this the best way, if not what is?

i’m open to all comments.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:19:31+00:00Added an answer on May 26, 2026 at 9:19 am

    set up your AJAX call to the php script within a JS function, and the last line of the function should be setTimeout(functionname, 10000);

    oh, and, you’ll need to call the function the first time somewhere, then it will continue to run…so:

    <html><head>
    <script>
    function update(){
    //your ajax here
    setTimeout(update,10000);
    }
    update();
    </script></head>
    <body><div id="theDivToUpdate"></div></body></html>
    

    Here’s some sample code to show you how you could pass JSON or XML and have the HTML page handle it. Here’s the PHP (here the data is just hardcoded, but in your case you’d dynamically populate):

    <?php
    $format=$_REQUEST['format'];
    if($format=="json"){
        header('Content-type: application/json');
        header('Cache-Control: no-cache, must-revalidate');
        echo "{\"status\":\"ok\",\"results\":[{\"first\":\"MyFirst\",\"last\":\"MyLast\",\"company\":\"Big Company\"},{\"first\":\"YourFirst\",\"last\":\"YourLast\",\"company\":\"Another Company\"},{\"first\":\"John\",\"last\":\"Doe\",\"company\":\"What Company?\"},{\"first\":\"Jane\",\"last\":\"Doe\",\"company\":\"Stackoverflow\"}]}";
    }
    else if($format=="xml"){
        header("Content-type: text/xml");
        header('Cache-Control: no-cache, must-revalidate');
        echo "<ROOT><STATUS>ok</STATUS><RESULTS><RESULT><FIRST>MyFirst</FIRST><LAST>MyLast</LAST><COMPANY>Big Company</COMPANY></RESULT><RESULT><FIRST>YourFirst</FIRST><LAST>YourLast</LAST><COMPANY>Another Company</COMPANY></RESULT><RESULT><FIRST>John</FIRST><LAST>Doe</LAST><COMPANY>What Company?</COMPANY></RESULT><RESULT><FIRST>Jane</FIRST><LAST>Doe</LAST><COMPANY>Stackoverflow</COMPANY></RESULT></RESULTS></ROOT>";
        }
    
    else{
        echo "You need to supply the \'format\' parameter (json or xml)";
    }
    ?>
    

    and then here is a sample html page:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script>
    
    function getJSON(){
            var xmlhttp;
            xmlhttp=((window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP"));
            xmlhttp.onreadystatechange=function()
            {
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    var res=xmlhttp.responseText; //THE JSON STRING IS TEXT
                    res=JSON.parse(res);  //THIS CONVERTS THE JSON INTO OBJECTS THAT CAN BE ACCESSED WITH DOT NOTATION
                    if(res.status=="ok"){
                        newtable="<table><tr><th>First</th><th>Last</th><th>Company</th></tr>";
                        for(i=0;i<res.results.length;i++){
                            newtable+="<tr><td>"+res.results[i].first+"</td><td>"+res.results[i].last+"</td><td>"+res.results[i].company+"</td></tr>";
                        }
                        newtable+="</table>";
                        document.getElementById('resultDiv').innerHTML=newtable;
                    }
                }
            }
            xmlhttp.open("GET","thePHPFile.php?format=json",true);
            xmlhttp.send();
    }
    
    function getXML(){
            var xmlhttp;
            xmlhttp=((window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP"));
            xmlhttp.onreadystatechange=function()
            {
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    res=xmlhttp.responseXML;
                    firstNameFields=res.documentElement.getElementsByTagName("FIRST"); //THESE LINES GRAB ALL OF THE NODES WITH THE INDICATED NAME AND HOLD THEM IN ARRAYS
                    lastNameFields=res.documentElement.getElementsByTagName("LAST");
                    companyFields=res.documentElement.getElementsByTagName("COMPANY");
                    newtable="<table><tr><th>First</th><th>Last</th><th>Company</th></tr>";
                    for(i=0;i<firstNameFields.length;i++){
                        newtable+="<tr><td>"+firstNameFields[i].firstChild.nodeValue+"</td><td>"+lastNameFields[i].firstChild.nodeValue+"</td><td>"+companyFields[i].firstChild.nodeValue+"</td></tr>";
                    }
                    newtable+="</table>";
                    document.getElementById('resultDiv').innerHTML=newtable;
                }
            }
            xmlhttp.open("GET","thePHPFile.php?format=xml",true);
            xmlhttp.send();
    }   
    
    </script>
    </head>
    
    <body>
    <input type="button" onclick="getJSON()" value="Retrieve and Parse JSON" />
    <input type="button" onclick="getXML()" value="Retrieve and Parse XML" />
    <div id="resultDiv"></div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to Refresh a Div in Page by Jquery <? if($POST['id']) :?> <script>
I have written a PHP script which allows me to modify and update a
i need to refresh combo box (sub category ) related to what i choose
I am using expandable listview i need to refresh as i am searching the
i need to check whether the user clicking the browser Refresh button and redirect
I need to add a shake feature that will refresh my Android application. All
I need to find whether the user clicking the browser back button or Refresh
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either
Need to locate the following pattern: The letter I followed by a space then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.