亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        純JavaScript實現AJAX

        字號:


            純JavaScript實現AJAX。具體代碼如下:
            window.lcq = {};
            (function(obj) {
            obj = {};
            //創(chuàng)建xmlhttprequest對象
            obj.createXMLHttpRequest = function() { if (window.ActiveXObject) { 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 { return new ActiveXObject(aVersions[i]); } catch (oError) { continue; } } } else if (window.XMLHttpRequest) { return new XMLHttpRequest(); } throw new Error("XMLHttp object could not be created."); }
            //ajax
            obj._xmlHttp = null;
            obj.ajax = function(options) {
            try {
            obj._xmlHttp = this.createXMLHttpRequest();
            obj._xmlHttp.open(options.method, options.url, true);
            obj._xmlHttp.setRequestHeader("cache-control", "no-cache");
            obj._xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            obj._xmlHttp.onreadystatechange = function() {
            if (obj._xmlHttp.readyState == 4) {
            if (obj._xmlHttp.status == 200) {
            var _response = "";
            switch (options.dataType.toLowerCase()) {
            case "json":
            _response = eval(obj._xmlHttp.responseText);
            break;
            case "xml":
            _response = obj._xmlHttp.responseXML;
            break;
            case "html":
            _response = obj._xmlHttp.responseText;
            break;
            default:
            _response = obj._xmlHttp.responseText;
            break;
            }
            options.success(_response);
            }
            }
            else { }
            }
            obj._xmlHttp.send(options.data);
            }
            catch (e) { }
            }
            //提示信息的方法
            obj.show = function(message) { alert(message); }
            //對象引用
            lcq = obj;
            $ = obj;
            })(lcq);
            //簡單的用法
            function _testAjax(obj) {
            obj.disabled = true;
            obj.value = "正在提交......";
            $.ajax({ url: "/xmls/url.xml",
            method: "GET",
            data: "",
            dataType: "html",
            success: function(response) {
            obj.disabled = false;
            obj.value = "處理完畢";
            //show(response);
            },
            error: function(response) { alert(response); }
            });
            }
            function show(message) {document.getElementById("wraper").innerHTML = message;}
            //html部分
            <div id="wraper">
            </div>
            <input type="button" value="Ajax測試" onclick="_testAjax(this);" />