Reputation: 139
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/
Upvotes: 1
Views: 2254
Reputation: 139
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
Upvotes: 0
Reputation: 924
function autoRefresh_div() {
$("#result").html('<object data="https://static.pexels.com/photos/17679/pexels-photo.jpg"/>'); // a function which will load data from other file after x seconds
alert('working');
}
setInterval(autoRefresh_div, 5000); // refresh div after 5 sec
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="result"></div>
This will load the page ever 5.
Upvotes: 1