通过php和js代码实现页面数据实时刷新

代码区
0 103
amm88
amm88 2021-07-29 10:52:17
极品小组

首先我们创建两个文件"amm88.htm"和"amm88.php",用htm编写js代码实现获取PHP里的数据

amm88.htm

<head>

<script>
// Refresh code
r_s = 0;
timenow = 0;
function calrs()
{
    d = new Date();
    h= d.getHours(); m = d.getMinutes(); s = d.getSeconds();

    if( m < 10) m = '0' + m;
    if( s < 10) s = '0' + s;
    status = ' ' + h + ":" + m + ":" + s;
    r_s = 2000;
}

calrs();

function reload_me()
{
    c = document.getElementById("reload1");
    c.src = "";
    c.src = "amm88.php?reload=1";

    calrs();

    setTimeout('reload_me()', r_s);
}

// Refresh code
setTimeout('reload_me()', r_s);
</script>

<script id="reload1"></script>

</head><small>
<div id="p_show></div>

</small>


 

amm88.php

<?php
header("Cache-Control: no-cache, must-revalidate");
 echo "document.all.p_show.innerHTML= \"?<font color=red>".rand(0,9)."</font>\"";
?>


回帖
回复列表