zoukankan      html  css  js  c++  java
  • AjaxDemo

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    <input type="button" id="bnt" value="请求"/>
    <div id="d1"></div>
    <script type="text/javascript">
        var bnt=document.getElementById('bnt')
        bnt.onclick=function (){
        //  1 创建对象
            var oAjax=null;
            if(window.XMLHttpRequest){
                oAjax=new XMLHttpRequest()
            }else{
                oAjax=new ActiveXObject("Microsoft.XMLHTTP")
            }
        //  2 连接服务器
            oAjax.open("GET","http://101.201.252.11/mt/main.php?case=news_list&hid=0?t="+Math.random(),true);
        //  3 发送请求
            oAjax.send(null)
        //接受服务器返回
            oAjax.onreadystatechange=function (){
    
                if(oAjax.readyState==4){
                   if(oAjax.status==200){
                        console.log("开始处理数据");
                       var arr = JSON.parse(oAjax.responseText);
                       var data=arr.data_list;
                       console.log(data[3].content);
                       d1.innerHTML=data[3].content;
                       //console.log();
                        //arr.split(",")
                        //alert(arr[3])oAjax.responseText
                        //alert(oAjax.responseText)
                   }else{
                       alert("请求失败")
                   }
                }
            }
        }
    </script>
    </body>
    </html>
  • 相关阅读:
    7. Reverse Integer
    2. Add Two Numbers
    1039. 顺序存储二叉树
    Codeforces 535D
    Codeforces 385D
    URAL
    URAL
    Codeforces Round #428 (Div. 2)
    鹰蛋坚硬度实验
    Codeforces Round #392 (Div. 2)-D. Ability To Convert
  • 原文地址:https://www.cnblogs.com/littlewriter/p/6371508.html
Copyright © 2011-2022 走看看