zoukankan      html  css  js  c++  java
  • new XMLHttpRequest()和页面关系

    1.  三个页面分别对应"自己“的异步对象(3个)

        <title></title>
        <script type="text/javascript">
            
            function GetXHR() {
                return new XMLHttpRequest();
            };
            var po = function () {
                var xhr = GetXHR();
                xhr.open("get", "PageOne.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("po").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            var pt = function () {
                var xhr = GetXHR();
                xhr.open("get", "PageTwo.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("pt").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            var pth = function () {
                var xhr = GetXHR();
                xhr.open("get", "PageThree.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("pth").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            window.onload = function () {
                pth();//Three
                po();//One
                pt();//Two
            };
        </script>
    </head>
    <body>
        <div id="po" style="background-color: #ffd800;"></div>
        <div id="pt" style="background-color: #4cff00;"></div>
        <div id="pth" style="background-color: #b6ff00;"></div>
    </body>
       //另外两个页面类似。
    public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //System.Threading.Thread.Sleep(1000); context.Response.Write("Hello World"); context.Response.Write("<br/>This is PageOne !!! <br/>" + "Second: " + DateTime.Now.Second + "<br/>Millisecond: " + DateTime.Now.Millisecond); }

    结果:

    改为一个对象

        <script type="text/javascript">
            var xhr = false;
            function GetXHR() {
                return new XMLHttpRequest();
            };
            var po = function () {
                //var xhr = GetXHR();
                xhr.open("get", "PageOne.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("po").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            var pt = function () {
                //var xhr = GetXHR();
                xhr.open("get", "PageTwo.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("pt").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            var pth = function () {
                //var xhr = GetXHR();
                xhr.open("get", "PageThree.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("pth").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            window.onload = function () {
                xhr = GetXHR();
                pth();//Three
                po();//One
                pt();//Two
            };
        </script>
    </head>
    <body>
        <div id="po" style="background-color: #ffd800;"></div>
        <div id="pt" style="background-color: #4cff00;"></div>
        <div id="pth" style="background-color: #b6ff00;"></div>
    </body>

    结果:

    调试:

    请求都进目标页面了,却”没带回来“数据

    如果慢慢的调试:

    结果一样

    一个对象(简短时间)多次请求同一个页面

       <script type="text/javascript">
            var xhr = false;
            function GetXHR() {
                return new XMLHttpRequest();
            };
            var po = function () {
                //var xhr = GetXHR();
                xhr.open("get", "PageOne.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("po").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            var pt = function () {
                //var xhr = GetXHR();
                xhr.open("get", "PageOne.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("pt").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            var pth = function () {
                //var xhr = GetXHR();
                xhr.open("get", "PageOne.ashx", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("pth").innerHTML = xhr.response;
                    }
                };
                xhr.send(null);
            };
            window.onload = function () {
                xhr = GetXHR();
                pth();//Three
                po();//One
                pt();//Two
            };
        </script>
    </head>
    <body>
        <div id="po" style="background-color: #ffd800;"></div>
        <div id="pt" style="background-color: #4cff00;"></div>
        <div id="pth" style="background-color: #b6ff00;"></div>
    </body>

    不同对象请求相同页面:

  • 相关阅读:
    ms sql 生成日历储存过程
    基于开源的GOCW和Directshow.net,实现摄像头预览、采集、录像等操作
    xshell链接远程服务器centos7显示-bash-4.2#
    docker服务日志查看方法
    信息技术应用技巧:没有音箱怎么办?手机当音箱
    信息技术应用技巧:台式机没有网线怎么办?
    C# 查找PDF页面指定区域中的文本并替换和高亮
    Java 将Excel工作簿按工作表拆分为多个文档
    Java 查找并替换PDF中的指定文本
    【SqlServer】导入MaxMind中的IP数据(.csv)文件到SQL Server数据库(转)
  • 原文地址:https://www.cnblogs.com/wjshan0808/p/3665319.html
Copyright © 2011-2022 走看看