• 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();
                }
            }
        }
    }

  • 相关阅读:
    mybatis SQL 根据in条件语句排序
    Redis面试总结
    数据库优化之分库分表
    jdk1.6 Synchronized 优化总结
    CounDownLatch、CyclicBarrier、Semaphore
    java锁总结
    Redis 与 MySQL 双写一致性如何保证
    dubbo总结
    一、全国大学生电子设计竞赛测控(无人机)方向___基础篇
    编解码KL变换详解和哥伦布k阶编解码
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1678707.html
Copyright © 2020-2023  润新知