zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }
    }

  • 相关阅读:
    筛法“四不像”——《C解毒》试读
    五花八门的main()
    新编《守株待兔》—C语言版—兼聊为什么不应该用%d格式转换输出指针
    含糊之过、多做之过及乱做之过
    怎样调戏程序
    混乱是怎样炼成的——《C解毒》试读
    到处忙活与一劳永逸
    “函数声明”、“函数原型”与“函数定义”辨析
    关于函数原型的对话
    内裤外穿——错位及不伦不类
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1678707.html
Copyright © 2011-2022 走看看