关闭

PHP AJAX

标签: ajax动态显示PHP
325人阅读 评论(0) 收藏 举报
分类:

zidong.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>标题动态</title>
</head>
<body>
<h1>Ajax动态显示时间</h1>
<input type="button" value="开始显示时间" id="go"  />
当前时间:<font color="red"><span id="showtime"></span></font><br/>
当前时间:<font color="red"><span id="showtime2"></span></font>
</body>
<script type="text/javascript">
    var xmlHttp;
    var goID=document.getElementById("go");
    goID.onclick=function(){
        start();
    }
    function createXMLHttpRequest(){
        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;
                var result = xmlHttp.responseText;
                result = result.split('|');
//                alert(result[0]);
//                alert(result[1]);
                document.title = result[1];
                document.getElementById("showtime2").innerHTML =  result[2];
                setTimeout("start()",1000);
            }
        }
    }
</script>
</html>

getTime.php


<?php
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("北京时间Y年m月d日H:i:s",$nowTime);
if($showtime<="北京时间1970年01月01日08:00:00"){
    echo "happy new year";
}
echo $showtime."|";
$db=new mysqli();
$db->connect("localhost","root",12345,"test");
$otime=microtime(true);
$db->query("set names 'utf8'");
$sql="select title,content from category where id=1";
$result=$db->query($sql);
$rs=$result->fetch_array();

echo $rs['title']."|";
echo $rs['content'];
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:85361次
    • 积分:1893
    • 等级:
    • 排名:千里之外
    • 原创:101篇
    • 转载:85篇
    • 译文:2篇
    • 评论:3条
    文章分类
    最新评论