//响应客户端Ajax调用

//一、不带返回值
function AjaxReq(url,httpMethod)
{
	var xmlHttp	= false;
	
	if(!httpMethod)
	{
		httpMethod = "GET";
	}
	
	xmlHttp	= CreateXmlRequest();							//创建 xmlhttp 对象
	
	if(!xmlHttp)
	{
		return; 											//创建 xmlhttp 对象失败
	}
	
	xmlHttp.open(httpMethod,url,true);						//提交客户端请求
	
	xmlHttp.onreadystatechange = function(){StateCon(xmlHttp);};
	
	//xmlHttp.setRequestHeader("If-Modified-Since","0");	//清除缓存，解决刷新数据不更新问题
	
	xmlHttp.send(null);
}

//二、带返回值
function AjaxRequest(url,httpMethod,Obj_ID)
{
	var xmlHttp	= false;
	var ShowObj	= "";
	
	ShowObj	= document.getElementById(Obj_ID);
	
	if(!httpMethod)
	{
		httpMethod	= "GET";
	}
	
	xmlHttp	= CreateXmlRequest();							//创建 xmlhttp 对象
	
	if(!xmlHttp)
	{
		return; 											//创建 xmlhttp 对象失败
	}
	
	xmlHttp.open(httpMethod,url,true);						//提交客户端请求
	
	xmlHttp.onreadystatechange	= function(){StateContent(xmlHttp,ShowObj);};
	
	//xmlHttp.setRequestHeader("If-Modified-Since","0");	//清除缓存，解决刷新数据不更新问题
	
	xmlHttp.send(null);
}

//处理返回信息的函数(判断状态：4是已发送，200是已完成)
function StateCon(xmlHttp)
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {           
            //释放浏览器内存开始
            delete xmlHttp;
            
			xmlHttp	= null;
			
			CollectGarbage;
			//释放浏览器内存结束
        }
//		else
//		{
//			alert("HTTP 错误，状态码：" + xmlHttp.status);
//		}
    }
//	else
//	{
//		alert("客户端 HTTP 请求发送失败，状态码：" + xmlHttp.readyState);
//	}
}

function StateContent(xmlHttp,ShowObj)
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {
            MakeOperate(xmlHttp,ShowObj);
           
            //释放浏览器内存开始
            delete xmlHttp;
            
			xmlHttp	= null;
			
			CollectGarbage;
			//释放浏览器内存结束
        }
//		else
//		{
//			alert("HTTP 错误，状态码：" + xmlHttp.status);
//		}
    }
//	else
//	{
//		alert("客户端 HTTP 请求发送失败，状态码：" + xmlHttp.readyState);
//	}
}

//给Ajax调用标签赋值
function MakeOperate(xmlHttp,ShowObj)
{
	//注：“responseText”如果写成“responsetext”在FireFox下将出现“undifine”异常，但在IE下可正常运行。
	ShowObj.innerHTML = xmlHttp.responseText;
}

//-------------------------------------------------------------------------------------------------------------------------------//

//创建xmlhttp_request响应实例
function CreateXmlRequest()
{
	var xmlhttp_request = false;
	
	try
	{
		if(window.ActiveXObject)		//针对FF(Mozallia:FireFox)浏览器
		{
			for(var i = 5; i; i--)
			{
				try
				{
					if(i == 2)
					{
						xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP");   
					}
					else
					{
						xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP." + i + ".0");
						xmlhttp_request.setRequestHeader("Content-Type","text/xml");
						xmlhttp_request.setRequestHeader("Content-Type","GBK");
					}
				
					break;
				}
				catch(e)
				{
					xmlhttp_request = false;
				}
			}
		}
		else if(window.XMLHttpRequest)		//针对IE(Microsoft:Internet Explorer)浏览器
		{
			xmlhttp_request = new XMLHttpRequest();
		
			if(xmlhttp_request.overrideMimeType)
			{  
				xmlhttp_request.overrideMimeType('text/xml');
			}
		}
	}
	catch(e)
	{
		xmlhttp_request = false;
	}
	
	return xmlhttp_request;
}