﻿/*应用Ajax*/
HTTPRequest = function () 
{
   var xmlhttp=null;
   try 
   {//IE浏览器
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//创建XMLHTTP对象
   }
   catch (_e) 
   {
      try 
	  {//Firefox/Mozilla浏览器         
		 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");//创建XMLHTTP对象
       }
	   catch (_E)
	   { }
   }
   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
   {
     try 
	 {
        xmlhttp = new XMLHttpRequest();
     } 
	 catch (e) 
	 {
        xmlhttp = false;
   	  }  
   }
   return xmlhttp;
}

function SeadAjax(url, obj)
{//执行文件,obj：为显示结果的对象
	  var http = new HTTPRequest();
   	  //http.open("GET", url, false);
	  http.open("GET", url, true);
	  http.onreadystatechange = function (){ handleHttpResponse(http, obj)};
	  http.setRequestHeader("If-Modified-Since","0"); //清除缓存
	  http.send();
}

function handleHttpResponse(http, obj)
{//输出结果,obj：为显示结果的对象
  if (http.readyState == 4)
  {
    result = http.responseText;
   	if ( -1 != result.search("null") ) 
	{
		obj.innerHTML = "";//没有相关信息
	} 
	else 
	{
		obj.innerHTML = result;
	} 	
   } 
}

function PostAjax(url, objName,str)
{//执行文件,obj：为显示结果的对象，str提交的内容
      var obj = document.getElementById(objName);
	  var http = new HTTPRequest();
   	  //http.open("GET", url, false);
	  http.open("POST", url, true);
	  http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	  http.onreadystatechange = function (){ handleHttpResponse(http, obj)};
	  //http.setRequestHeader("If-Modified-Since","0"); //清除缓存
	  //发送数据
	  http.send(str);
	  //http.send("title="+escape(title)+"&content="+escape(content));
}

//
//获取内容
//
function getInfo(url, objName)
{//获取url的内容,objName：为显示内容的对象名称
	var obj = document.getElementById(objName);
	obj.innerHTML = "Lonig……";
	SeadAjax(url, obj);
}

