zoukankan      html  css  js  c++  java
  • XMLHttpRequest ajax调用无刷新显示后台时间

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>

    代码
      <script type="text/javascript" >
        
    var timeout = null//setInterval函数句柄   
        var xmlHttp = false// 
        function SendRequest()
        {
            
    //xmlHttp = false; 
            if (window.ActiveXObject)
            {   
                
    try 
                {
                    xmlHttp 
    = new ActiveXObject("Msxml2.XMLHTTP");
                }    
                
    catch (e) 
                {
                    xmlHttp 
    = new ActiveXObject("Microsoft.XMLHTTP");
                }   
            }
            
    else if (window.XMLHttpRequest) 
            {
                xmlHttp 
    = new XMLHttpRequest();
            } 
            
    else
            {
                alert(
    '初始化错误!');
                
    return;
            }
            
    var url = "Handler.ashx";
            
    //var url = "Default2.aspx";
            xmlHttp.open("GET",url,true);
            xmlHttp.onreadystatechange 
    = ShowData;
            xmlHttp.send(
    null);
        }
        
    function ShowData()
        {
            
    if(xmlHttp.readystate == 4)
            {
                
    if(xmlHttp.status == 200)
                {
                    
    var tag = document.getElementById("container");
                    tag.innerHTML 
    = "";
                    tag.innerHTML 
    = xmlHttp.responseText;
                }  
            }
        }

        
    //开始自动刷新   
        function Update() 
        {   
            timeout 
    = window.setInterval("SendRequest()"1000);//设定1秒调用一次Default2.aspx页面   
        }   
        
    //停止自动刷新   
        function StopUpdate() 
        {   
            
    if (timeout != null
            {   
                window.clearInterval(timeout);   
            }   
        }
    </script>

    <body onload="SendRequest();">
        <form id="form1" runat="server">
        <div>
            <input type="button" value="Start Fresh" onclick="Update();"/> 
            <input type="button" value="Stop Fresh" onclick="StopUpdate();"/>
            <input id="Button1" type="button" value="确定" onclick="SendRequest();"/>
        </div>
        </form>
        <div id="container"><!--容器--></div>
    </body>
    </html>

    每天进步一点点...

  • 相关阅读:
    [BZOJ5338][TJOI2018]xor(可持久化Trie)
    [BZOJ4592][SHOI2015]脑洞治疗仪(线段树)
    [BZOJ4571][SCOI2016]美味(贪心+主席树)
    [BZOJ4570][SCOI2016]妖怪(凸包)
    [BZOJ4569][SCOI2016]萌萌哒(倍增+并查集)
    [BZOJ4567][SCOI2016]背单词(Trie+贪心)
    [BZOJ4565][HAOI2016]字符合并(区间状压DP)
    [BZOJ4561][JLOI2016]圆的异或并(扫描线)
    [BZOJ2650]积木
    [清橙A1210]光棱坦克
  • 原文地址:https://www.cnblogs.com/cyan/p/1271349.html
Copyright © 2011-2022 走看看