zoukankan      html  css  js  c++  java
  • AJAX实时刷新数据、状态显示、局部刷新示例

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!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 runat="server">
        
    <title>Untitled Page</title>
        
    <script language=Javascript>        
           function SetMessage()
           
    {
            _Default.GetServiceStatus(GetMessage_CallBack);
           }
            
           function GetMessage_CallBack(response)
           
    {
            var btn 
    = document.getElementById('<%=btnSet.ClientID%>');
            var btnPanel 
    = document.getElementById('btnPanel');
            var lbl 
    = document.getElementById('lblStatus');
            var status 
    = response.value;
            
    switch(status)
            
    {
                
    case "Running":
                    lbl.innerText 
    = "运行中";
                    btn.value 
    = "停止";
                    btnPanel.style.visibility 
    = "visible";
                    
    break;
                
    case "Stopped":
                    lbl.innerText 
    = "已停止";
                    btn.value 
    = "启动";
                    btnPanel.style.visibility 
    = "visible";
                    
    break;
                
    case "StartPending":
                    lbl.innerText 
    = "正在启动";
                    btnPanel.style.visibility 
    = "hidden";
                    
    break;
                
    case "StopPending":
                    lbl.innerText 
    = "正在停止";
                    btnPanel.style.visibility 
    = "hidden";
                    
    break;
            }

           }

        
    </script>
    </head>
    <body onload="setInterval('SetMessage()',100);">
        
    <form id="form1" runat="server">
        
    <table>
            
    <tr><td width="250"><div id="lblStatus"></div></td><td>
                
    <div id="btnPanel" style="visibility:visible"><asp:Button ID="btnSet" runat="server" Text="Button" OnClick="btnSet_Click1" /></div></td></tr>
        
    </table>
        
    </form>
    </body>
    </html>
    protected void Page_Load(object sender, EventArgs e)
        
    {
            Ajax.Utility.RegisterTypeForAjax(
    typeof(_Default));       
        }


        [Ajax.AjaxMethod()]
        
    public string GetServiceStatus()
        
    {
            
    return ctl.Status.ToString();
        }
  • 相关阅读:
    根据浏览器是否出现滚动条,显示返回顶部
    HTML5 屏蔽触屏滚动
    url参数中带有+号,服务器端解码之后没了
    jQuery1.9之后使用on()绑定 动态生成元素的 事件无效
    列表页复选框全选效果
    Python安装sqlite3
    python3.5中,import sqlite3 出现 no module named _sqlite3的解决方法
    使用js设置input标签只读 readonly 属性
    怎么获得当前点击的按钮的id名?
    JS 浮点型数字运算(转)
  • 原文地址:https://www.cnblogs.com/netwom/p/950342.html
Copyright © 2011-2022 走看看