Home >
Backend Development >
PHP Tutorial >
A brief analysis of the implementation summary of the partial refresh function of PHP pages_PHP tutorial
A brief analysis of the implementation summary of the partial refresh function of PHP pages_PHP tutorial
WBOY
Release: 2016-07-21 15:04:20
Original
1415 people have browsed it
There are actually quite a few methods. In the past, iframe was more commonly used. Now there is an additional ajax, so ajax is generally used. The first method, ajax implementation: Of course, ajax is really simple to use and can be implemented, but a lot of the knowledge in it is still a bit deep. I used ajax to automatically refresh the page time. The complete code is: 1.getTime.php:
Copy the code The code is as follows:
header("cache-control:no-cache,must-revalidate"); header("Content-Type:text/html;charset=utf-8"); $time = "2012-1-20 18:00:00"; $dt_element=explode(" ",$time); $date_element=explode("-",$dt_element[0]); $time_element=explode(":",$dt_element[1]); $date = mktime($time_element[0],$time_element[1],$time_element[2],$date_element[1] ,$date_element[2],$date_element[0]); $nowTime = time(); $showtime = date("H:i:s, m, month, d, year Y, Beijing time",$date -$nowTime); if($showtime<="Beijing time, January 1, 1970 08:00:00"){ echo "happy new year"; } echo $ showtime;
2.zidong.php:
Copy code The code is as follows:
Ajax dynamic display time
Current time:
> if(window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); } } function start(){ createXMLHttpRequest(); var url="getTime.php"; xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange = callback; xmlHttp.send(null); } function callback(){ if(xmlHttp.readyState == 4){ if(xmlHttp. status == 200){ document.getElementById("showtime").innerHTML = xmlHttp.responseText; setTimeout("start()",1000); } } }