php refresh just a part of the page
try this
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#Status').load('record.php');
}, 1000); // refresh every 1000 milliseconds
</script>
<body>
<div id="Status"></div>
</body>
make new php file record.php and put your countdown code in it, it will refresh div every second
Refresh a page using PHP
You can do it with PHP:
header("Refresh:0");
It refreshes your current page, and if you need to redirect it to another page, use following:
header("Refresh:0; url=page2.php");
reload a specific section of a web page
Inside the success of your ajax, replace the html of your old post div with new post content. $("#old_post_div").html("new_post_content");
Or you can use prepend or append so that the new content will be prepended or appended along with old content.
How to refresh a specific div of a page in PHP?
function refresh_box()
{
$("#myDiv").load('path your PHP file');
setTimeout(refresh_box, 60000);
}
$(document).ready(function(){
refresh_box();
});
this setTimeout
call your function for every 1 minute and load content dynamically in mydiv
.
refresh part of php page
To refresh only part of a webpage you can use AJAX. It is based on JavaScript and lets you update certain parts of a webpage without reloading it.
Here you can learn more: https://www.w3schools.com/js/js_ajax_intro.asp
Refresh Part of Page (div)
Use Ajax for this.
Build a function that will fetch the current page via ajax, but not the whole page, just the div in question from the server. The data will then (again via jQuery) be put inside the same div in question and replace old content with new one.
Relevant function:
http://api.jquery.com/load/
e.g.
$('#thisdiv').load(document.URL + ' #thisdiv');
Note, load automatically replaces content. Be sure to include a space before the id selector.
How to auto refresh a section of a page
You could use a Javascript library such as jQuery and do something like the following simplified example:
$("document").ready(function(){
var interval = setInterval(refresh_box(), 60000);
function refresh_box() {
$("#myDiv").load('path/to/databasepage.php');
}
} /*<= The closer ) bracket is missing in this line*/
and in your path/to/databasepage.php
page you can have your select query and echo the results out.
What this does is sets a timeout to call a function (in this case, refresh_box()
) every 60 seconds (which is 60,000 miliseconds) and loads the data from path/to/databasepage.php
in to your div with the id myDiv
.
edit:
If you want to stop the auto-refresh you can bind an element to clear the interval by doing the following:
// assuming you have a clickable element
// (typically a button or so) id called 'stop_refresh'
$("#stop_refresh").click(function(){
clearInterval(interval);
}
Related Topics
Sending Data Using Post in Python to PHP
Does Perl Have PHP-Like Dynamic Variables
What Is Difference of Developing a Website in MVC and 3-Tier or N-Tier Architecture
Shell Run/Execute PHP Script with Parameters
How to Replace the Text of a Node Using Domdocument
Multi-Dimensional Array Post from Form
How to Use Curl to Fetch Specific Data from a Website and Then Save It My Database Using PHP
How to Select Multiple Files for Upload
Pdo Bindparam into One Statement
Updating Column So That It Contains the Row Position
500 Server Error: Premature End of Script Headers:
Http://Localhost/ Not Working on Windows 7. What's the Problem
How to Check in PHP That I'm in a Static Context (Or Not)