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

  • 相关阅读:
    PerfDog WEB端使用手册
    PerfDog4.0探索,支持用户自建web云
    无AI不测试:人工智能时代背景下,如何发展与应用自动化测试?
    性能测试实践 | PerfDog助力微信小游戏/小程序性能调优
    mysql面向过程学习
    阿里云操作记录
    socket网络编程
    学习慕课广告系统
    xinhuadouxxx总结
    maven+springboot+mybatis快速搭建简单使用
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1678707.html
Copyright © 2011-2022 走看看