自己写的一个无刷新,消息提示功能大屏查看

发布于:2015年07月06日 已被阅读

自己写的一个无刷新,消息提示功能


html页面

<!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=utf-8" /><title>消息提示</title><script src="jquery-1.7.1.min.js"></script><script>//var i=0;function messagetishi($i){ var xhr;     //定义一个ajax的对象  var text="localhost";  //表 单中国的的值,要通过url参数进行一步传送  var url="chuli.php?loc="+"localhost"+"&user="+"root"+"&pw="+""+"&i="+$i;                                  //异步传送内容                  xhr=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");//定义一个浏览器的通用对象  xhr.open("POST",url,true);//打开提交地址及其提交方法,和异步  xhr.send(null);//发送请求  xhr.onreadystatechange=function()     //监听  {if(xhr.readyState==4)                                //事件追踪,看执行到哪了    {  if(xhr.responseText != 0){      //i++;     // alert(xhr.responseText); if($i==1){     document.getElementById("messages").innerHTML="<font color='green'>"+xhr.responseText+"</font><br />"+"<a href='javascript:void(0)' onclick='location.reload()'>返回首页</a>"; document.getElementById("message").innerHTML="<font color='red'>以下是您的消息!</font>"; }     else { document.getElementById("message").innerHTML="<font color='red'>您有"+xhr.responseText+"未读消息!</font>";}  }    }   }}function sx(){setInterval("messagetishi()",500);}</script></head><body onload="sx()"><span id="message" style="color:#009966; background-color:#FFCC99; cursor:pointer" onclick="messagetishi(1)">您目前没有消息</span><div id="messages" style="background-color:#FFCC99"></div></body>
</html>


处理页面chuli.php

<?php
$i=0;
$loc=$_REQUEST['loc'];
$user=$_REQUEST['user'];
$pw=$_REQUEST['pw'];
mysql_connect("$loc","$user","$pw") or die("链接有问题");
mysql_select_db("test") or die("连接数据库失败");
$sql="select *from a where status=1;";
$res=mysql_query($sql);
$str="";
while($rows=mysql_fetch_assoc($res)){
  $str.=$rows['name']."---<hr />";
  $i++;
}
if($_REQUEST['i']==1){
   $sql="update a set status=0 where status=1;";
   $rr=mysql_query($sql);
   if($rr){echo $str;}
}else{
if($i != 0){
 echo $i;
}
else{
 echo 0;
}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。


最新发布
linux下svn提交忽略某些文件... (173)
使用批处理来批量更新、提交SVN... (136)
linux查看目录文件大小命令 (146)
linux tar打包压缩排除某个... (134)
Linux tar压缩和解压 (192)
SVN子命令add用法浅析 (130)
热门博文
网友FBI探案:马蓉iPad惊人发现... (43345)
霍金携手俄罗斯富豪耗资1亿美元寻找外... (4747)
如何才能查看PHP内置函数源代码... (1210)
微信支付开发当前URL未注册的解决方... (575)
《谁为爱情买单》中的经典面试 ... (441)
让虚拟主机也用上SVN:适用于个人的... (395)
精华博文
[推荐]Centos7 安装配置 SVN (159)
easyswoole框架安装 (174)
php开启pecl的支持(推荐) (157)
1-10个恋爱表现:男朋友爱你程度到... (164)
女生喜欢你的10个程度,到第六个就可... (141)
Eclipse 没有Server选项... (211)
友情链接
我来忙 (110)