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">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> dynamic display time </title>
</Head>
<Script language = "javascript">
Var xmlHttp;
Function createXMLHttpRequest (){
If (window. ActiveXObject ){
XmlHttp = new ActiveXObject ("microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XmlHttp = new XMLHttpRequest ();
}
Else {
Alert ("failed to create request ");
}
}
Function sendRequest (){
CreateXMLHttpRequest ();
Url = "time_check.php ";
XmlHttp. onreadystatechange = callback;
XmlHttp. open ('get', url, true );
XmlHttp. send (null );
}
Function callback (){
If (xmlHttp. readyState = 4 ){
If (xmlHttp. status = 200 ){
Document. getElementById ("time"). innerHTML = xmlHttp. responseText;
SetTimeout ("sendRequest ()", 1000 );
}
}
}
</Script>
<Body>
<Input type = "button" value = "check it" onclick = "sendRequest ();"/>
<Br/>
<Span id = "time"> </span>
</Body>
</Html>
Server code:
Copy codeThe Code is as follows:
<? Php
Header ("cache-control: no-cache, must-revalidate"); // cancel the php page cache settings
Header ('content-type: text/html; charset = GB2312 ');
$ Showtime = date ("Beijing time, Y, m, D, H: I: s ");
Echo $ showtime;
?>