简体   繁体   English

PHP - 自动刷新页面

[英]PHP - auto refreshing page

I am using following code for a refreshing page, it is not reloading on completion.我正在使用以下代码刷新页面,完成后不会重新加载。 The following code is not working sometime.以下代码有时不起作用。

 $page = $_SERVER['PHP_SELF'];
 $sec = "10";
 header("Refresh: $sec; url=$page");
 echo "Watch the page reload itself in 10 second!";

Use a <meta> redirect instead of a header redirect, like so:使用<meta>重定向而不是标头重定向,如下所示:

<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
?>
<html>
    <head>
    <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
    </head>
    <body>
    <?php
        echo "Watch the page reload itself in 10 second!";
    ?>
    </body>
</html>

you can use您可以使用

<meta http-equiv="refresh" content="10" > 

just add it between the head tags只需将其添加到 head 标签之间

where 10 is the time your page will refresh itself其中 10 是您的页面将自行刷新的时间

使用此代码,它会在 5 秒后自动刷新,您可以在刷新中更改时间

<?php $url1=$_SERVER['REQUEST_URI']; header("Refresh: 5; URL=$url1"); ?>

Try out this as well.也试试这个。 Your page will refresh every 10sec您的页面将每 10 秒刷新一次

<html>
 <head>

  <meta http-equiv="refresh" content="10; url="<?php echo $_SERVER['PHP_SELF']; ?>">
 </head>
 <body>

 </body>
</html>

Maybe use this code,也许使用此代码,

<meta http-equiv="refresh" content = "30" />

take it be easy放轻松

Simple step like this,像这样简单的步骤,

<!DOCTYPE html>
<html>
<head>
    <title>Autorefresh Browser using jquery</title>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
            startRefresh();
        });
        function startRefresh() {
            setTimeout(startRefresh,100);
            $.get('text.html', function(data) {
                $('#viewHere').html(data);
            });
        }
    </script>

</head>
<body>
    <div id="viewHere"></div>
</body>
</html>

This video for complete tutorial https://youtu.be/Q907KyXcFHc此视频完整教程https://youtu.be/Q907KyXcFHc

This works with Firefox Quantum 60+ and Chrome v72 (2019)这适用于 Firefox Quantum 60+ 和 Chrome v72 (2019)

//set a header to instruct the browser to call the page every 30 sec
header("Refresh: 30;");

It does not seem to be NECESSARY to pass the page url as well as the refresh period in order to (re)call the same page.为了(重新)调用同一页面,似乎没有必要传递页面 url 和刷新周期。 I haven't tried this with Safari/Opera or IE/Edge.我还没有在 Safari/Opera 或 IE/Edge 上试过这个。

<meta http-equiv="refresh" content="10" >

This can work.这可以工作。 Try it..!!尝试一下..!! :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM