﻿/*****************************************************************************
 *                     XMLHTTP请求类
 *属性：
 *      method(String)：请求方法，POST或者GET，默认为GET
 *         url(String)：请求URL，默认为空
 *      async(Boolean)：是否异步，true为异步，false为同步，默认为true
 *     content(String)：请求的内容，如果请求方法为POST需要设定此属性，默认为空
 *  callback(Function)：回调函数，即返回响应内容时调用的函数，默认为直接返回。
 *                      回调函数有一个参数为XMLHttpRequest对象，即定义回调函数
 *                      时要这样：function callBackFunction(XMLHttpRequest)
 *                                  {alert(XMLHttpRequest.responseText);}
 *方法：
 *  send()：发送XMLHTTP请求，无参数
 *
 *作者：心云意水
 *时间：2007.1.17
 *Email:xinyunyishui@eyou.com
 ****************************************************************************/
function eyunXMLHttp()
  {var xmlHttpObj=false;
   var ObjSelf=this;
   try 
     {xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP");
     }
   catch(e)
     {try
        {xmlHttpObj=new ActiveXObject("MSXML2.XMLHTTP");
        }
      catch(e1)
        {try
           {xmlHttpObj=new XMLHttpRequest;
           }
         catch(e2)
           {xmlHttpObj=false;
           }
        }
     }
   if (!xmlHttpObj)
     {throw(new Error(-1,"无法创建XMLHTTP连接对象！"));
      return false;
     }
   this.method="GET";
   this.url;
   this.async=true;
   this.content="";
   this.callback=function(xhr){return;}
   this.send=function()
     {if(!this.method||!this.url||!this.async)
        {throw(new Error(-1,"method、url、async属性不能为空！"));
         return false;
        }
      xmlHttpObj.open(this.method,this.url,this.async);
      if(this.method=="POST")
        xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      xmlHttpObj.onreadystatechange=function()
        {if(xmlHttpObj.readyState==4)
           if(xmlHttpObj.status==200)
             ObjSelf.callback(xmlHttpObj);
           else             
             {if(confirm("页面读取错误，是否现实详细错误信息？"))
                {var tmpwindowserror=window.open("","tmpwindowserror","");
                 tmpwindowserror.document.open();
                 tmpwindowserror.document.write(xmlHttpObj.responseText);
                 tmpwindowserror.document.close();
                }
              throw(new Error(-1,"页面读取错误！"));
             }
        }
      if(this.method=="POST")
        xmlHttpObj.send(this.content);
      else
        xmlHttpObj.send(null);
     }
  }
