zoukankan      html  css  js  c++  java
  • ajax的基本使用

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>ajax</title>
    </head>
    <body>
        
        <button id='but'>ajax的基本使用</button>
        <script type="text/javascript">
        //获取元素对象
        var but = document.getElementById('but');
    
        but.onclick = function()
        {
            // 1.创建ajax对象
            if(window.XMLHttpRequest){
    
                //现在平常使用的浏览器
                var x = new XMLHttpRequest();
            } else {
                //ie5和ie6浏览器使用
                var x = new ActiveXObject('Microsoft.XMLHTTP');
            }
    
            //2.绑定事件  on 当...时候 readystate 对象属性  change改变
                //alert(x.readyState);
            x.onreadystatechange = function()
            {
                //alert(x.readyState);
                if(x.readyState == 4 && x.status == 200){
    
                    //服务器返回的结果
                    console.log(x.responseText);
                    // alert(x.responseText);
                }
            }
    
    
            //3.初始化  方法中的参数有3个 
                        // 1.请求的方式(GET POST)
                        // 2.服务器的文件
                        // 3.同步还是异步
            x.open('GET','1.php',true);
    
            //4.发送
            x.send();
        }
    
    
    
        </script>
    </body>
    </html>
  • 相关阅读:
    [HDU6793] Tokitsukaze and Colorful Tree
    [NOI2020]命运
    [NOI2020]美食家
    模拟9
    晚测2
    模拟8
    联考4
    模拟7
    模拟6
    关于数论
  • 原文地址:https://www.cnblogs.com/xujing6/p/6390209.html
Copyright © 2011-2022 走看看