if(/msie/i.test(navigator.userAgent)) {
    window.XMLHttpRequest=function(){
        var ver=['MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','MICROSOFT.XMLHTTP.1.0','MICROSOFT.XMLHTTP.1','MICROSOFT.XMLHTTP','MSXML2.XMLHTTP.5.0'];
		for(var i=0;i<ver.length;i++){try{return new ActiveXObject(ver[i])} catch(e){}};
        return null;
    };
}

$ajax={
    send : function(arg){
        var XHR = new XMLHttpRequest();
        if(XHR==null){return alert("浏览器不支持xmlhttp")}
        if(XHR.overrideMimeTyp)XHR.overrideMimeType('text/xml');
        var dataType = {text:'responseText',xml:'responseXML',json:'responseText'};
        var options = {
            url : '',type : 'GET',async : true,
            data : null,timeout : 0,
            contentType : 'application/x-www-form-urlencoded',
            encoding : 'UTF-8', dataType : 'text',
            State : ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'],
            ErrorState :{"400": "Bad Request 请求出现语法错误",
                "404": "无法找到指定位置的资源",
                "405": "type Not Allowed 请求方法（GET、POST、HEAD、DELETE、PUT、TRACE等）对指定的资源不适用"},
            create : function(){},success : function(){},
            doing : function(){}, ontimeout: function(){},end:function(){},
            error : function(status,ErrorMsg,eMsg){alert("Status: "+status+"\nErrors: "+ErrorMsg+"\n        "+eMsg);}
        }
	var ex=function(main,ex){for(var k in (ex||{}))main[k]=ex[k];return main}
       ex(options,arg||{});
        options.url += ((options.url.indexOf("?")>0)?"&":"?")+"_=" + (+new Date);
        options.type = options.type.toUpperCase();
        if(options.async){
            options.doing(0,options.State[0]);
            XHR.onreadystatechange=function(){
                var _state = XHR.readyState;
                options.doing(_state,options.State[_state]);
                switch(_state){
                    case 0:
                        options.create(_state,options.State[_state]);break;
                    case 4:
						options.end.call(XHR);
                        if(XHR.status == 200)
                            options.success(options.dataType == "json" ? eval("("+XHR[dataType[options.dataType]]+")") : XHR[dataType[options.dataType]],_state,options.State[_state]);
                        else if( XHR.status >200 )
                            options.error(XHR.status,options.ErrorState[XHR.status],"");
                        XHR.onreadystatechange = function(){};
                        XHR = null;break;
                }
            };
        };
        try{
            XHR.open(options.type, options.url, options.async);
            if(options.type=="POST")
                XHR.setRequestHeader('Content-Type', options.contentType+'; charset='+options.encoding);
            if(options.async && options.timeout>0){
                setTimeout(function(){
                    try{if(XHR!=null && XHR.readyState!=4)  options.ontimeout();XHR.abort();XHR=null;
                    } catch(e){}},options.timeout);
            }
            XHR.send(options.data);
            if(!options.async){options.success(XHR[dataType[options.dataType]]);options.end.call(XHR);XHR=null}
        }
        catch(e){
            try{options.error(XHR.status,options.ErrorState[XHR.status],e);}
            catch(e){options.error(0,"",e)}
            finally{XHR&&XHR.abort();XHR=null}
        }
    }
}

ajax=function (ini){return $ajax.send(ini)}; 
