• javascript Ajax类


    //////////////////////////////////
    //Ajax类
    //////////////////////////////////
    function MyAjax(){
        this.method = "POST";
        this.url = "";
        this.parameter = "";
        this.sync = true;
        this.transfers = function(obj){return ;};
        this.waiting = function(){return ;};
        if(this.xmlhttp = this.createXmlhttp()){
            this.stateChange();
        }
    }

    MyAjax.prototype = {//创建xmlhttprequest
        msxml : ['Msxml2.XMLHTTP','Microsoft.XMLHTTP'],
        createXmlhttp : function(){
            if(window.XMLHttpRequest){
                xmlhttp = new XMLHttpRequest();
                if(xmlhttp.overrideMimeType){
                    xmlhttp.overrideMimeType('text/plain');
                }
            }else if(window.ActiveXObject){
                try {
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }catch(e){
                    try {
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }catch(e){}
                }
            }
            return xmlhttp;
        },
        send : function(){
            if(this.method == 'GET'){
                this.xmlhttp.open(this.method,this.url+'?'+this.parameter,this.sync);
                this.xmlhttp.send();
            }else{
                this.xmlhttp.open(this.method,this.url,this.sync);
                this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
                this.xmlhttp.send(this.parameter);
            }
        },
        stateChange : function(){
            var _self = this;
            _self.xmlhttp.onreadystatechange = function(){
                if(_self.xmlhttp.readyState == 4){
                    if(_self.xmlhttp.status == 200){
                        _self.transfers(_self.xmlhttp.responseText);
                    }
                }else{
                    _self.waiting();
                }
            }
        }
    }

  • 相关阅读:
    [Swift]LeetCode811. 子域名访问计数 | Subdomain Visit Count
    [Objective-C语言教程]程序结构(3)
    [Objective-C语言教程]开发环境设置(2)
    [Objective-C语言教程]简介(1)
    [Swift]LeetCode810. 黑板异或游戏 | Chalkboard XOR Game
    [Swift]LeetCode809. 情感丰富的文字 | Expressive Words
    [Swift]LeetCode808. 分汤 | Soup Servings
    转:用ANT执行SQL
    转:让开发自动化: 实现自动化数据库迁移
    转 让开发自动化: 使用自动化加速部署
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1678707.html
Copyright © 2020-2023  润新知