zoukankan      html  css  js  c++  java
  • ajax数据格式HTML

    做了个小例子。基本的XMLHttpRequest操作都有,只是从HTML传数据。

    index.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript">
    window.onload = function(){
        var anodes = document.getElementsByTagName("a");
        for(var i = 0; i<anodes.length; i++){
            anodes[i].onclick = function(){
                var request = new XMLHttpRequest();
                var method = "GET";
                var url = this.href;
                request.open(method,url);
                request.send(null);
                
                request.onreadystatechange = function(){
                    if(request.readyState == 4){
                        if(request.status == 200||request.status == 304)
                            {
                            document.getElementById("details").innerHTML =request.responseText;
                            }
                    }
                }
                
                return false;
            }
        }
    }
    </script>
    </head>
    <body>
    <ul>
    <li><a href="file/1.html"> 购物网站 </a></li>
    <li><a href="file/2.html"> 学习网站 </a></li>
    <li><a href="file/3.html"> 视频网站 </a></li>
    </ul>
    <div id="details">
    
    </div>
    </body>
    </html>

    1.html

    <h2><a href="https://www.taobao.com/">taobao</a></h2>
    <a href="https://www.tmall.com/">tianmao</a>

    2.html

    <h2><a href="https://www.w3school.com.cn/">w3cschool</a></h2>
    <a href="https://www.runoob.com/">runoob</a>

    3.html

    <h2><a href="https://www.bilibili.com/">bilibili</a></h2>

    结果截图:

  • 相关阅读:
    再谈HTTP通信
    【ZOJ】[1586]QS Network
    【ZOJ】[1586]QS Network
    【POJ】[2421]Constructing Roads
    【POJ】[2421]Constructing Roads
    【POJ】[2031]Building a Space Station
    【POJ】[2031]Building a Space Station
    【POJ】[1287]Networking
    【POJ】[1287]Networking
    【杭电】[1875]畅通工程再续
  • 原文地址:https://www.cnblogs.com/a155-/p/12433723.html
Copyright © 2011-2022 走看看