﻿/*
*********************************************************************************
xmlhttp类--by 锋.David

创建方法：var xmlhttpobj=new xmlhttp;	如果创建失败则返回false,不进行下一步的操作

属性：content -  请求的内容，默认为空
　　　callback  - 返回响应内容时调用的函数

方法：go(url,true||false)     -  请求的参数(url请求的地址,是否异步)
	  send()     -  发送请求，无参数

<script type="text/javascript" src="xmlhttp.js"></script>	//加载xmlhttp类

<script type="text/javascript">
var xmlhttpobj=new xmlhttp;	// 创建xmlhttp对象
xmlhttpobj.go("xxxx.asp?act=123",true);	// 设置请求的参数(url请求的地址,是否异步)
xmlhttpobj.content="kk=456&pp=789";	//请求的内容,以POST的方式发出去
xmlhttpobj.send();	// 发送请求
xmlhttpobj.callback=function(xmlobj)	// 返回响应内容函数，输出返回响应内容
	{
		//xmlobj.responseText;
		//对返回的内容进行操作

		xmlobj=null;
		xmlhttpobj=null;
	}
</script>

xxxx.asp 页例子
<%
response.write request("act")
response.write request.form("kk")
response.write request.form("pp")
%>
*********************************************************************************
*/
function xmlhttp()
{
	var xmlObj = false;
	var ObjSelf;
	var asyncobj,urlobj;
	ObjSelf=this;
	try
	{
		xmlObj=new XMLHttpRequest;
	}
	catch(e)
	{
		try
		{
			xmlObj=new ActiveXObject("MSXML2.XMLHTTP");
		}
		catch(e2)
		{
			try
			{
				xmlObj=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e3)
			{
				xmlObj=false;
			}
		}
	}
	if (!xmlObj) return false;
	this.go=function (url,async)
		{
			if (async=="" || async==null) async=true;
			asyncobj=async;
			urlobj=url;
		}
	this.content="";
	this.callback=function(cbobj) {return;}
	this.send=function()
		{
			if(!urlobj) return false;
			if(asyncobj=="" || asyncobj==null) asyncobj=true;
			xmlObj.open ("POST", urlobj, asyncobj);
			xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			if (asyncobj==true)
			{
				xmlObj.onreadystatechange=function()
					{
						if(xmlObj.readyState==4)
						{
							//if(xmlObj.status==200)
							//{
								ObjSelf.callback(xmlObj);
							//}
						}
					}
			}
			xmlObj.send(this.content);
			if (asyncobj==false)
			{
				if(xmlObj.readyState==4)
				{
					//if(xmlObj.status==200)
					//{
						ObjSelf.callback(xmlObj);
					//}
				}
			}
		}
}
