原始的ajax操作

var xmlHttp = null ;
        //创建XMLHttpRequest对象
        function createXMLHttp() {
            if (typeof XMLHttpRequest != "undefined") //针对非IE浏览器
            {
                xmlHttp = new XMLHttpRequest();
            }
            else if (window.ActiveXObject)//针对IE浏览器 
            {
                var aVersions = ["Msxml2.XMLHttp.5.0", "Msxml2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0", "Msxml2.XMLHttp", "Microsoft.XMLHttp"];
                for (var i = 0; i < aVersions.length; i++) {
                    try {
                        xmlHttp = new ActiveXObject(aVersions[i]);
                        break;
                    }
                    catch (e)
        { }
                }
            }
        }
 
        function sendRequest() {
//……
             createXMLHttp(); //0
            // alert(xmlHttp.readyState);
             xmlHttp.onreadystatechange = function () {
                 // alert(xmlHttp.readyState);
                 if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                     //得到响应流
                     var result = xmlHttp.responseText;
                     sp.innerHTML = result;
}
                 }
             };
             //注意谓词 最好大写
             xmlHttp.open("GET", url, true); //连接服务器 readyState  0>1
             xmlHttp.send(null); //发送请求1>2  >>>3 参数 发送的数据(post提交)
         }
        
原文地址:https://www.cnblogs.com/hui1107464497/p/4502156.html