How to partial refresh a include php page?
<?php include("news.php"); ?>
Hello, I include a news.php
in my main page index.php
. I want to refresh t开发者_Go百科he news.php
every 30 seconds, but not refresh the main page index.php
, How to partial refresh a include php page? Thanks.
I've been searching for something similar and it's taken a while but I think this might work:
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
setInterval(function() {
$("#screen").load('news.php')
}, 2000);
});
</script>
Another way to refresh an include (Valid only if the include only contains variables and their values):
<?php
$config = file_get_contents("news.php");
$config = str_replace("<?php", "", $config);
$config = str_replace("?>", "", $config);
eval($config);
?>
Very easy method to refresh include (only for backend single user, not for frontend):
<?php
$t = time();
rename("news.php", "news_${t}.php");
include("news_${t}.php");
rename("news_${t}.php", "news.php");
?>
精彩评论