• ajax小demo


    var oDiv = document.getElementById("div1");
                document.onclick = function(){

                    //var xhr = new XMLHttpRequest(); //创建XHR对象
                    var xhr;
                    if(window.XMLHttpRequest){
                        xhr = new XMLHttpRequest();//创建了一个XHR对象;
                    }else{
                        xhr = new ActiveXObject("MSxml12.XMLHTTP");//兼容IE6以下
                    }
                    
                    
                    xhr.open("get","demo.php",true); //准备发送请求 第一个参数:get/post 第二个:url 第三个:true(异步)

                    // 设置回调函数
                    xhr.onreadystatechange = function(){
                        if(xhr.readyState==4){
                            if(xhr.status==200){
                                // alert(xhr.responseText);
                                div1.innerHTML = xhr.responseText;
                            }else{
                                alert("error,restart");
                            }
                        }
                    }

                    // 发送请求
                     xhr.send(null); //get方式发送请求,send参数就是null
                }

                //兼容:
                // new AativeXObject("MSxml2.XMLHTTP") //IE6 IE5
                // new XMLHttpRequest(); //其他浏览器;
                //如果有就创建
                var request;
                if(window.XMLHttpRequest){
                    request = new XMLHttpRequest();//创建了一个XHR对象;
                }else{
                    request = new ActiveXObject("MSxml12.XMLHTTP");//兼容IE6以下
                }

  • 相关阅读:
    scrapy中selenium的应用
    Django的锁和事务
    redis
    【leetcode】187. Repeated DNA Sequences
    【leetcode】688. Knight Probability in Chessboard
    【leetcode】576. Out of Boundary Paths
    【leetcode】947. Most Stones Removed with Same Row or Column
    【leetcode】948. Bag of Tokens
    【leetcode】946. Validate Stack Sequences
    【leetcode】945. Minimum Increment to Make Array Unique
  • 原文地址:https://www.cnblogs.com/yuejie/p/5986030.html
Copyright © 2020-2023  润新知