﻿var Float = true;
var AjaxReturnType=0;
var AjaxCommand;
function AjaxPro(div)
{
    var XMLhttp = this.Init();
	var AjaxShowDiv=this.$(div);
    
    
    this.Load = function(method,HttpUrl,value)
    {
	    if(value==null){}
	     XMLhttp.open(method,HttpUrl, Float);
	     XMLhttp.onreadystatechange = this.Process;
	    var https=null;
	    if(method=="Post")
	    {
		    XMLhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		    https = value;
	    }
	     XMLhttp.send(https);
    }
    this.Process = function()
    {
       
	    if(XMLhttp.readyState == 4)
	    {
		    if(XMLhttp.status == 200)
		    {
			    var ReturnValue= XMLhttp.responseText;
			    if(AjaxReturnType==0)
			    {
 				    AjaxShowDiv.innerHTML = ReturnValue
			    }
			    if(AjaxReturnType==1)
			    {
				    //执行某个方法
				    eval(AjaxCommand(ReturnValue));
			    }
     			
		    } else
		    {
			    var ReturnValue = "HTTP 错误，状态码：" +  XMLhttp.status;
			    AjaxShowDiv.innerHTML =ReturnValue;
		    }
	    }
    }
    this.Get = function(HttpUrl)
    {
	    if(HttpUrl.indexOf("?")==-1)
	    {
		    this.Load("Get",HttpUrl+"?rndmath="+Math.floor(Math.random()*10));
	    }else{
		    this.Load("Get",HttpUrl+"&rndmath="+Math.floor(Math.random()*10));
       }
    }
    this.Post = function(HttpUrl,value)
    {
	    this.Load("Post",HttpUrl,value);
	    return 1;
    }
}
AjaxPro.prototype.$ = function(id){return document.getElementById(id);}
AjaxPro.prototype.Init = function()
    {
	    var xmlhttp;
		    try
		    {
			    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		    }
		    catch (e)
		    {
			    try
			    {
				    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			    catch (e)
			    {
				    xmlhttp = false;
			    }
		    }
		    if (!xmlhttp && typeof XMLHttpRequest!='undefined')
		    {
			    try
			    {
				    xmlhttp = new XMLHttpRequest();
			    }
			    catch (e)
			    {
				    xmlhttp=false;
			    }
		    }
		    if (!xmlhttp && window.createRequest)
		    {
			    try
			    {
				    xmlhttp = window.createRequest();
			    }
			    catch (e)
			    {
				    xmlhttp=false;
			    }
		    }
		    return xmlhttp;
    }
