PHP AJAX
2015-07-10 11:17
543 查看
zidong.html
getTime.php
<!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'];
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- 解决Ajax悬停效果,无法遮蔽FLASH的问题
- IE:如何做到全屏显示
- 修改注册表实现在桌面上显示Windows版本
- 再谈Jquery Ajax方法传递到action(补充)
- Dom在ajax技术中的作用说明
- C#动态调整数组大小的方法
- Attrib 显示、设置或删除指派给文件或目录的只读、存档、系统以及隐藏属性
- PHP+Apache在Windows 9x下的安装和配置
- 使用Ajax实时检测"用户名、邮箱等"是否已经存在
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充