一个简单的 Ajax 类

var Configuration = {
 MaxHttpRequest : 3
}

function Ajax()
{
 this.Version = "1.0.1";
 this.Query = new Array(Configuration.MaxHttpRequest);

 this.RequestCount = 0;
 this.XmlHttp = null; 
}

Ajax.prototype.Create = function(){
 try{
  this.XmlHttp = new XMLHttpRequest();
 }
 catch (error){
  try{
   this.XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (error){
   alert('Cannot create ajax object');
   return null;
  }
 } 
}

Ajax.prototype.Send = function(method, url, callback)
{
 this.Create();
 if (null == this.XmlHttp)
 {
  return;
 } 
 this.XmlHttp.open(method, url, true); 
 this.XmlHttp.onreadystatechange = callback; 
 this.XmlHttp.send(null);
}
 

原文地址:https://www.cnblogs.com/AloneSword/p/2237543.html