zoukankan      html  css  js  c++  java
  • 无刷新效果统计在线人数

        <script src="js/jquery-1.9.1.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                function GetUser() {
                    WebApplication1.WebService1.GetCountPerson(onSuccess, onFailed);
                    
                }
                function onSuccess(result) {
                    $('#spcount').text(result);
                }
                function onFailed() {
                    $('#spcount').text('获取失败');
                }


                setInterval(GetUser, 2000);
            
            })
        </script>


    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
          <Services>
            <asp:ServiceReference Path="~/WebService1.asmx" />
          </Services>
        </asp:ScriptManager>
        <div>
             <div>当前在线总人数:<span id="spcount"></span></div>
        </div>
        </form>

    </body>

     

    WebService

      [WebMethod]         public string GetCountPerson()         {             return Application["count"].ToString();          }

     

    Global

     protected void Application_Start(object sender, EventArgs e)         {             Application["count"] = 0;         }
            protected void Session_Start(object sender, EventArgs e)         {             int count = Convert.ToInt32(Application["count"]);             count++;             Application["count"] = count;         }

  • 相关阅读:
    自己实现的一个简单的C# IOC 容器
    C# 内存缓存工具类 MemoryCacheUtil
    使用触发器和C#程序实现数据同步
    Maven 命令安装指定 jar 包到本地仓库
    C# RSA 非对称加密
    JS可选链操作符?.和双问号??
    Learn D3 入门文档: Introduction
    Lerna 基本概念
    图片 src 为二进制的处理
    ASCII 和 Base64
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/3092292.html
Copyright © 2011-2022 走看看