﻿var $=function(tagName){return document.getElementById(tagName);}
function Ajax2009() {
	this.xmlhttp = false;
	if(window.XMLHttpRequest) { 
		this.xmlhttp = new XMLHttpRequest();
		if (this.xmlhttp.overrideMimeType)
			this.xmlhttp.overrideMimeType("text/xml");
	}
	else if (window.ActiveXObject) {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	this.GetData = function(url, obj, callback) {
	    var self = this;
	    if (!this.xmlhttp) { alert("请更新你的浏览器"); return; }
	    this.xmlhttp.onreadystatechange = function() {
	        if (self.xmlhttp.readyState == 4) {
	            if (self.xmlhttp.status == 200) {
	                if (typeof callback == "function") {
	                    if (!callback(self.xmlhttp.responseText)) {
	                        return;
	                    }
	                }
	                if ($(obj)) $(obj).innerHTML = self.xmlhttp.responseText;
	            }
	            else
	                if ($(obj)) $(obj).innerHTML = "加载失败";
	        }
	    }
	    this.xmlhttp.open("GET", url, true);
	    this.xmlhttp.setRequestHeader("If-Modified-Since", "0");
	    this.xmlhttp.send(null);
	}
	
	this.PostData = function(url, data, callback,name,content) {
		var self = this;
		if(!this.xmlhttp) { alert("请更新你的浏览器"); return; }
		this.xmlhttp.onreadystatechange = function() {
			if (self.xmlhttp.readyState == 4) {
				if (self.xmlhttp.status == 200) {
	                if (typeof callback == "function") {
	                    callback(self.xmlhttp.responseText,name,content);
	                }
	            }
	            else
	            {
	                if(typeof errorCallback == "function")
	                {
	                    errorCallback(self.xmlhttp.responseText);
	                }
	            }
			}
		}
		this.xmlhttp.open("POST", url, true);
		this.xmlhttp.setRequestHeader("If-Modified-Since", "0");
		this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.xmlhttp.send(data);
	}
}