﻿var Request = {

  inited: false,
  xmlHttp: null,
  callback: null,
  
  init: function()
  {
    if (window.ActiveXObject) {   
        this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
    }   
    else if (window.XMLHttpRequest) {   
        this.xmlHttp = new XMLHttpRequest();   
    }
    else {
      alert("对不起,您使用的浏览器不支持XmlHttpRequest。");
    }
  },
  
  ReadyStateChange: function()
  {
    if(this.xmlHttp.readyState == 4 && this.callback) {
      this.callback(this.xmlHttp.responseText);
    }
  },
  
  send: function(url, post, callback)
  {
     if (!this.inited) {
       this.init();
       this.inited = true;
     }
     
     this.callback = callback || null;
     this.xmlHttp.open("POST", url, true);
     this.xmlHttp.onreadystatechange = this.ReadyStateChange.bind(this);
     this.xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     this.xmlHttp.send(post);
  }
};