开发者

How to partial refresh a include php page?

开发者 https://www.devze.com 2023-02-06 07:08 出处:网络
<?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, Ho
<?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");
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号