Ajax gets the current time dynamically (PHP)


Client code:

Copy codeThe code is as follows:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
< title > dynamic display time < / Title >
<script language=”javascript”>
var xmlHttp;
function createXMLHttpRequest(){
xmlHttp = new ActiveXObject(“microsoft.XMLHTTP”);
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
Alert (“create request failed”);
function sendRequest(){
url = “time_check.php”;
xmlHttp.onreadystatechange = callback;
function callback(){
if(xmlHttp.readyState ==4){
if(xmlHttp.status == 200){
document.getElementById(“time”).innerHTML = xmlHttp.responseText;
<input type=”button” value=”check it” onclick=”sendRequest();” />

Server side code:

Copy codeThe code is as follows:
header(“cache-control:no-cache,must-revalidate”); // Unset PHP page cache
header(‘Content-type: text/html;charset=GB2312’);
$Showtime = date (“H: I: s, m, D, Beijing time”);
echo $showtime;

Recommended Today

Redis featured Q & A

Redis data type type brief introduction characteristic scene String (string) Binary security It can contain any data, such as JPG pictures or serialized objects. One key can store up to 512M It can be used to do the simplest data. It can cache a simple string or a JSON format string. The implementation of redis […]