创建AJAX

来源:互联网 发布:淘宝订单贷款还款 编辑:程序博客网 时间:2024/06/06 06:29
  function createXmlHttp() {            var xhobj = false;            try {                //适配msxml3.0+(IE7.0及以上)                xhobj = new ActiveXObject("Msxml2.XMLHTTP");            } catch (e) {                try {                    //适配msxml2.6(IE5/6)                    xhobj = new ActiveXObject("Microsoft.XMLHTTP");                } catch (e2) {                    xhobj = false;                }            }            if (!xhobj && typeof XMLHttpRequest != 'undefined') {                //适配Firefox,safari,Opera8.0+等                xhobj = new XMLHttpRequest();            }            return xhobj;  }  var xhr;  window.onload = function () {        xhr = createXmlHttp();  }  function doAjax() {        xhr.open("GET", "Default.aspx?inpText=1", true);        xhr.onreadystatechange = watching;        xhr.send(null);  }  function watching() {        if (xhr.readyState >= 4) {           if (xhr.status == 200) {                var txta = xhr.responseText;                document.getElementById('divMsg').innerHTML = txta;           } else {                document.getElementById('divMsg').innerHTML = "服务器出错" + xhr.status;           }        }  }

0 0
原创粉丝点击