function Ajax() {

    var xmlHttp = null;
    var isDisposed = false;
    var requestHeaders = ({"Count" : 0, "Items" : {}});
    var username = "", password = "";
    
    this.Result = function (method, url, data) {
        //参数合法性判断
        if ("string" !== typeof(method)) {
            throw new Error("参数 method 必须是一个字符串类型的值！");
        }
        if ("string" !== typeof(url)) {
            throw new Error("参数 url 必须是一个字符串类型的值！");
        }
        
        //处理 method 参数
        method = method.toLowerCase();
        if ("get" !== method && "post" !== method) {
            method = "get";
        }
        
//        xmlHttp.onreadystatechange = function() {
//			if(http.readyState==4)
//				callbak(http);
//        };
                
        //执行一些初始化操作
        initXmlHttp();
        try {
            
            //打开 XmlHttp
//            if ("get" === method && "string" === typeof(data) && data.length > 0) {
                xmlHttp.open(method, url + ((-1 === url.indexOf("?")) ? "?" + data : "&" + data), false);//, username, password);
//            }else {
//                xmlHttp.open(method, url, username, password);
//            }
            
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
            if (requestHeaders.Count > 0) {
                for (var key in requestHeaders.Items) {
                    xmlHttp.setRequestHeader(key, requestHeaders.Items[key]);
                }
            }
            
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            
            if ("undefined" === typeof(data) || "" === data) {
                data = null;
            }
            
            xmlHttp.send(data);
        }catch($e) {
            xmlHttp.abort();
            throw $e;
        }
       	return xmlHttp.responseText;
    };
    
    /**
     * 发送 HTTP 请求
     */
    this.Request = function (method, url, data, callback, disableCache) {    	
        //参数合法性判断
        if ("string" !== typeof(method)) {
            throw new Error("参数 method 必须是一个字符串类型的值！");
        }
        if ("string" !== typeof(url)) {
            throw new Error("参数 url 必须是一个字符串类型的值！");
        }
        
        //处理 method 参数
        method = method.toLowerCase();
        if ("get" !== method && "post" !== method) {
            method = "get";
        }
        
        //执行一些初始化操作
        initXmlHttp();
        
        var async = ("function" === typeof(callback));
        try {
            //判断是否使用异步 XmlHttp 请求，如果是，则设置回调函数
            if (async) {
                xmlHttp.onreadystatechange = function () {
                    if (4 == xmlHttp.readyState) {
                        callback(xmlHttp.responseText);
                    }
                };
            }
            
            //打开 XmlHttp
            if ("get" === method && "string" === typeof(data) && data.length > 0) {
                xmlHttp.open(method, url + ((-1 === url.indexOf("?")) ? "?" + data : "&" + data), async, username, password);
            }else {
                xmlHttp.open(method, url, async, username, password);
            }
            
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            if (requestHeaders.Count > 0) {
                for (var key in requestHeaders.Items) {
                    xmlHttp.setRequestHeader(key, requestHeaders.Items[key]);
                }
            }
            
            //如果参数 disableCache 被设置为 true，则不缓存 XmlHttp 请求
            if (true === disableCache) {
                xmlHttp.setRequestHeader("If-Modified-Since", "0");
            }
            
            if ("undefined" === typeof(data) || "" === data) {
                data = null;
            }
            
            if ("get" === method) {
                xmlHttp.send(data);
            }else {
                xmlHttp.send(data);
            }
        }catch($e) {
            xmlHttp.abort();
            throw $e;
        }
        
        //如果为设置为异步 XmlHttp 请求，则返回 XmlHttp 实例的引用
        if (!async) {
            return xmlHttp;
        }
    };
    
    /**
     * 自动获取 Form 表单的数据并发送到服务端
     */
    this.SubmitForm =  function (form ,callback, disableCache) {
        //检查参数 form 是否是有效的表单对象的引用(此处的检查较简单)
        if (!form || "undefined" === typeof(form.tagName) || "form" !== form.tagName.toString().toLowerCase() || "undefined" === typeof(form.elements)) {
            throw new Error("参数 form 不是有效的表单元素的引用！");
        }
        
        var enctype = form.enctype.toString().trim().toLowerCase();
        if ("multipart/form-data" === enctype) {
            throw new Error("不支持带有文件上传功能的表单！");
        }
        
        //从 form 表单取得要提交的地址
        var url = form.action.toString().trim();
        if ("" === url) {                   //form.action 未填写
            url = window.location.href;
        }else if("?" === url.charAt(0)) {     //form.action 的第一个字符是“?”
            url = window.location.href.replace(window.location.search, "") + url;
        }
        
        //从 form 表单取得 method 的值
        var method = form.method.toString().trim().toLowerCase();
        if ("get" !== method && "post" !== method) {
            method = "get";
        }
        
        //处理 form 表单要提交的数据
        var data = "", seperator = "", ele = null, type = "";
        for (var i = 0; i < form.elements.length; i++) {
            ele = form.elements[i];
            if (ele.disabled) {
                continue;
            }else if ("" === ele.name) {
                continue;
            }else if ("select" === ele.name && -1 === ele.selectedIndex) {
                continue;
            }
            if (ele.type) {
                type = ele.type.toString().toLowerCase();
                if ("checkbox" === type && !ele.checked) {
                    continue;
                }else if ("radio" === type && !ele.checked) {
                    continue;
                }
            }
            data += seperator + ele.name + "=" + escape(ele.value);
            seperator = "&";
        }
        
        //设置 Cookie
        if (document.cookie) {
            this.SetRequestHeader("Cookie", document.cookie);
        }
        //设置 Content-Type
        this.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        //发送 HTTP 请求
        return this.Request(method, url, data ,callback, disableCache);
    };
    
    /**
     * 设置 HTTP 请求的头
     */
    this.SetRequestHeader = function (name ,value) {
        //参数判断
        if ("string" !== typeof(name)) {
            throw new Error("参数 name 不是合法的字符串类型的变量！");
        }
        if ("string" !== typeof(value)) {
            throw new Error("参数 value 不是合法的字符串类型的变量！");
        }
        
        requestHeaders.Count = requestHeaders.Count + 1;
        requestHeaders.Items[name] = value;
    };
    
    /**
     * 设置请求所需的用户名和密码
     */
    this.SetLoginInfo = function (uid, pwd) {
        if ("string" !== typeof(uid)) {
            return false;
        }
        if ("string" !== typeof(pwd)) {
            return false;
        }
        
        username = uid;
        password = pwd;
    };
    
    /**
     * 仅释放 XmlHttp 所占用的资源
     */
    this.Abort = function () {
        if (null != xmlHttp) {
            xmlHttp.abort();
        }
    };
    
    /**
     * 释放 XmlHttp 所占用的资源，并且使当前实例不可用
     */
    this.Dispose = function () {
        if (null == xmlHttp) {
            return null;
        }
        try {
            //将所有状态设为默认
            initialize();
            //设置 isDisposed 为 true
            isDisposed = true;
            //释放 XmlHttp 对象所占用的资源
            xmlHttp.abort();
            //取消回调，便于下次使用
            xmlHttp.onreadystatechange = null;
        }catch($e) {
        }
    };
    
    /**
     * 创建一个 XmlHttp 的实例
     */
    function createXmlHttp() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        }
        var msxml = ["Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
        for (var i = 0; i < msxml.length; i++) {
            try {
                return new ActiveXObject(msxml[i]);
            }catch($e) {
            }
        }
        return null;
    }
    
    /**
     * 初始化操作
     */
    function initialize() {
        //为 String 类型的原型增加一个 trim()
        if (!("trim" in String.prototype)) {
            String.prototype.trim = function () {
                return this.replace(/(^\s*)|(\s*$)/g, '');
            };
        }
        requestHeaders = ({"Count" : 0, "Items" : {}});
    }
    //初始化
    initialize();
	
	function initXmlHttp() {
	   //判断是否已调用过 Dispose()，如果是，则抛出异常
	   if (true === isDisposed) {
	       throw new Error("已调用过 Dispose 方法！");
	   }
	   //初始化私有变量 xmlHttp
	   if (null == xmlHttp) {
	       xmlHttp = createXmlHttp();
	       if (null == xmlHttp) {
	           throw new Error("您的浏览器不支持或未启用 XmlHttp ！");
	       }
	   }
	   
	   //如果 xmlHttp.readyState 的值为4，表明上次对 this.Request 的调用已结束，
	   //需要关闭 HTTP 连接，然后直接返回 xmlHttp
	   if (4 == xmlHttp.readyState) {
	       initialize();
	       xmlHttp.abort();
	       return xmlHttp;
	   }
	}
}

