javascriptphphtmlreloadajax-polling

Refresh a PHP required file within a specific intervals


I tried these:

    <div id="result">
<table>
<?php require('newses.php'); ?>
</table>
</div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
   <script>
 function autoRefresh_div()
 {
      $("#result").load("load.html");// a function which will load data from other file after x seconds
  }

  setInterval('autoRefresh_div()', 1000); // refresh div after 5 secs
            </script>    

But it didn't worked for me. Please visit these pages:

Reload the content of a div afer regular interval of time

http://devzone.co.in/automatically-refresh-html-page-div-specific-time-interval/


Solution

  • I found the answer my self. There was a small problem in my code. I was wanting my page to include newses.php file in my page, and refresh the same file (newses.php) after every 1 seconds. The JavaScript code had a small problem. The refresh page's code name was load.html,so that the browser tries to load load.html page after 1 sec of first web page loading. When I changed refresh code from $("#result").load("load.html");// a function which will load data from other file after x seconds to $("#result").load("newses.php");// a function which will load data from other file after x seconds, my page became totally working correctly. Here is the edited code.

    function autoRefresh_div() { $("#result").load("newses.php");// a function which will load data from other file after x seconds } setInterval('autoRefresh_div()', 1000); // refresh div after 5 secs