function createXmlhttp(){
var xmlhttp;
if(window.XMLHttpRequest){
  xmlhttp = new XMLHttpRequest();/*Microsoft IE*/
  if (xmlhttp.overrideMimeType){
   xmlhttp.overrideMimeType("text/xml");
  }
  
}
else if(window.ActiveXObject){
  try{
   xmlhttp = new  ActiveXObject("Msxml2.XMLHTTP");/*版本新的浏览器*/
  }catch(e){
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");/*版本旧的浏览器*/
  }
}
if(!xmlhttp){
  window.alert("您的浏览器不支持XMLHttpRequest!");/*不支持XMLHttpRequest*/
}
return xmlhttp;
}

var Request = new Object();
Request.send = function(url, method, callback, data, urlencoded) {
	var req = createXmlhttp();
	req.onreadystatechange = function() {
		if(req.readyState == 4){
			if (req.status < 400) {
				(method=="POST") ? callback(req) : callback(req,data);
			}else{
				alert("服务器繁忙请稍后再试!");
			}
		}
	}
	if (method=="POST") {
		req.open("POST", url, true);
		if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(data);
	} else {
		req.open("GET", url, true);
		req.send(null);
	}
	return req;
}
Request.sendRawPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data, false);
}
Request.sendPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data, true);
}
Request.sendGET = function(url, callback, args) {
	return Request.send(url, "GET", callback, args);
}






















/*
GET Requests
Example:

var req = new XMLHttpRequest();
if (req) {
  req.onreadystatechange = function() {
    if (req.readyState == 4 && req.status == 200) {
      alert(req.responseText);
    }
  };
  req.open('GET', 'pageurl.html');
  req.send(null);
} 



POST Requests
Example:

var req = new XMLHttpRequest();
if (req) {
  req.onreadystatechange = function() {
    if (req.readyState == 4 && req.status == 200) {
      alert(req.responseText);
    }
  };
  req.open('POST', 'scripturl.cgi');
  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  req.send('var1=data1&var2=data2');
}

*/
