无刷新随时取得用户当前活动信息

来源:互联网 发布:淘宝9.9疯抢领红包链接 编辑:程序博客网 时间:2024/05/22 00:38

最终显示是这样的:

用户:billy 权限:管理员 时间[2004年1月21日 20:54:08] 停留[0小时0分钟] 空闲[0分钟12秒]

显示的bottom.htm文件

<script language=javascript>
<!--
function bar()
{

    var oxmldoc = new activexobject(msxml);             //创建msxml对象

    surl = "loginxml.asp"      //获取登陆状态数据的地址

    oxmldoc.url = surl;     //load数据

    var oroot=oxmldoc.root;     //获取返回xml数据的根节点
    if(oroot.children != null) 

    {    

                    
              //根据返回的数据在客户端显示

              user.innerhtml=oroot.children.item(0).text;       //用户

              myclock.innerhtml=oroot.children.item(1).text;       //时间

              stay.innerhtml=oroot.children.item(2).text;    //停留

              free.innerhtml=oroot.children.item(3).text;    //空闲

              qx.innerhtml=oroot.children.item(4).text; //权限
             

    }
       if (oroot.children.item(5).text>1800)  //空闲时间超过30分钟则自动转到退出登陆页面
         window.parent.location="/user/logoff.asp?id=1";


              timeoutid = settimeout("bar()",1000)      //没1秒取得一次数据,}
//-->
</script>

用户:<font color="#ff0000"><span id=user></span></font> 权限:<font color="#ff0000"><span id=qx></span></font>  时间[<span id=myclock></span>] 停留[<span id=stay></span>] 空闲[<span id=free></span>]


提供xml数据的asp页面 loginxml.asp

<%
username=session("username")
qxdm=session("qxdm")
set rs = server.createobject("adodb.recordset")
    rs.source = "select * from userlogin  where username="&username&""
    rs.open rs.source,conn,1,1
    logindate=rs("logindate")
    active=rs("active")
    rs.close
    stay=datediff("s",logindate,now())
    off=datediff("s",active,now())
    stay=stay/60
    stay=int(stay/60)&"小时"&int(stay mod 60)&"分钟"
    free=int(off/60)&"分钟"&int(off mod 60)&"秒"
    us=datepart("yyyy",date)&"年"&datepart("m",date)&"月"&datepart("d",date)&"日 "&time
%>
<?xml version="1.0" encoding="gb2312" ?>

<plan>

       <user><%=username%></user>

       <date><%=us%></date>

       <active><%=stay%></active>

       <free><%=free%></free>
      
       <qx><%call qx(qxdm)%></qx>
      
       <off><%=off%></off>
</plan>


本来觉得这样会占用很多的资源,但是实际应用时觉得一切正常