﻿/*
XMLHTTP同步和异步取数据类
编码者         fj
建立日期       2008-12-12
最后修改者     fj
最后修改日期   2008-12-12
*/
 var Browser = {

    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  }
function XMLHTTPHelper(requestType,requestUrl,params,syncallback){
	var chkUrl = requestUrl + params;
	
	if(Browser.IE)
	{
	this.xh = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
	if(window.XMLHttpRequest)
	{
	this.xh = new XMLHttpRequest();
	}
	}
	
	this.GetResult = function(){
		return this.xh.responseText
	}
	this.GetReadyState = function(){
		return this.xh.readyState
	}
	this.GetStatus = function(){
		return this.xh.status
	}
	this.OnReadyStateChange = eval(syncallback)
	if(syncallback!=null){
		this.xh.onreadystatechange = this.OnReadyStateChange;
	}
	//
	this.RequestDataIsSyn = function(){
		switch(requestType.toLocaleLowerCase()){
			case "get":
				this.xh.open(requestType,chkUrl,true);
				this.xh.send();
			break;
			case "post":
				this.xh.open(requestType,requestUrl,true);
				this.xh.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				this.xh.send(params);
			break;
		}
	}
	this.RequestData = function(){
		switch(requestType.toLocaleLowerCase()){
			case "get":
				this.xh.open(requestType,chkUrl,false);
				this.xh.send();
			break;
			case "post":
				this.xh.open(requestType,requestUrl,false);
				this.xh.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				this.xh.send(params);
			break;
		}
		return this.GetResult()
	}
}
