国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
創(chuàng)建xmlhttp請(qǐng)求&管理請(qǐng)求
var Bind = function(object, fun) {
    var args = Array.prototype.slice.call(arguments).slice(2);
    return function() {
          return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
     }
}

var Request = function() {
    this.requestexe = this.getNewRequest();
    this.action = 'get';
    this.url = '';
    this.ondone = null;
    this.onerror = null;
    this.headers = null;
    this.body = null;
    this.isstart = false;
    this.timer = null;
    this.paras = null;
}
Request.prototype = {
    count : 0,
    getNewRequest : function(){
        try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
        try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
        try { return new XMLHttpRequest(); } catch(e) {}
        alert("XMLHttpRequest not supported");
        return null;
    },
    send : function(){
        if(this.isstart) return;
        if(this.getCount() > 1){
            setTimeout(Bind(this, this.send),500);
            return;
        }
        this.waitOne();
        this.isstart = true;
        this.url = this.url +  "&" + new Date().getTime().toString();
        this.requestexe.open(this.action,this.url,true);
        if(this.headers){
            for (var header in this.headers) {
                var val = headers[header];
                if (typeof(val) !== "function")
                    this.requestexe.setRequestHeader(header, val);
            }
        }
        if (this.action.toLowerCase() === "post") {
            if ((this.headers === null) || !headers['Content-Type']) {
                this.requestexe.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            }
                if (!this.body) {
                this.body = "";
            }
        }
        var request = this;
        var httpexe = this.requestexe;
        this.requestexe.onreadystatechange = function(){
            if(httpexe.readyState == 4){
                clearTimeout(request.timer);
                Bind(request,request.releaseOne());
                if(httpexe.status == 200){
                    if(typeof(request.ondone) === "function"){
                        request.ondone(httpexe,request.paras);
                    }
                }
                else{
                    if(typeof(request.onerror) === "function"){
                        request.onerror(httpexe,request.paras);
                    }
                }
            }
        }
        this.timer = setTimeout( function(){
            request.requestexe.abort();
            clearTimeout(request.timer);
            request.releaseOne();
        },20000);
        this.requestexe.send(this.body);
    },
    releaseOne: function(){
        if(Request.prototype.count >= 0)
        Request.prototype.count--;
    },
    waitOne:function(){
        Request.prototype.count++;
    },
    getCount:function(){
        return Request.prototype.count;
    }
}

在使用時(shí)如下:
    var request = new Request();
    request.action = 'get';
    request.url = 'requesturl';
    request.ondone = function(result,paras){
        var p = result.responseText;
    };
    request.onerror = function(result,paras){
        alert(result.status);
    };
    request.paras = '';
    request.send();       

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
追求簡(jiǎn)約而且簡(jiǎn)單的AJAX封裝:Prototype
Ajax與REST架構(gòu)簡(jiǎn)單示例
Ajax: Java BluePrints 和 Rails對(duì)它的封裝
prototype 源碼解讀的第二部分 - Ajax.js
ajax相關(guān)代碼錦集
控制臺(tái)測(cè)試ajax
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服