function CreateXmlHttpRequest(funNameHandler){
//funNameHandler 为异步状态事件处理函数
// init XmlHttpRequest
//xmlhttp和xmldom对像
this.xhttp = null;
this.xdom = null;
//post或get发送数据的键值对
this.keys = Array();
this.values = Array();
this.keyCount = -1;
//http请求头
this.rkeys = Array();
this.rvalues = Array();
this.rkeyCount = -1;
//请求头类型
this.rtype = 'text';
//初始化 xmlhttpRequest 对象
this.xhttp = CreateXmlHttpRe(funNameHandler);
//以下为成员函数
//--------------------------------
//初始化xmldom
this.InitXDom = function(){
var obj = null;
if (typeof(DOMParser) != "undefined") { // Gecko、Mozilla、Firefox
var parser = new DOMParser();
obj = parser.parseFromString (xmlText, "text/xml");
} else { // IE
try { obj = new ActiveXObject("MSXML2.DOMDocument");} catch (e) { }
if (obj == null) try { obj = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) { }
}
this.xdom = obj;
};
//增加一个POST或GET键值对
this.AddKey = function(skey,svalue){
this.keyCount++;
this.keys[this.keyCount] = skey;
this.values[this.keyCount] = escape(svalue);
};
//增加一个Http请求头键值对
this.AddHead = function(skey,svalue){
this.rkeyCount++;
this.rkeys[this.rkeyCount] = skey;
this.rvalues[this.rkeyCount] = svalue;
};
//清除当前对象的哈希表参数
this.ClearSet = function(){
this.keyCount = -1;
this.keys = Array();
this.values = Array();
this.rkeyCount = -1;
this.rkeys = Array();
this.rvalues = Array();
};
//发送http请求头
this.SendHead = function(){
if(this.rkeyCount!=-1){ //发送用户自行设定的请求头
for(;i<=this.rkeyCount;i++){
this.xhttp.setRequestHeader(this.rkeys[i],this.rvalues[i]);
}
}
if(this.rtype=='binary'){
this.xhttp.setRequestHeader("Content-Type","multipart/form-data");
}else{
this.xhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
};
//用Post方式发送数据
this.SendPost = function(purl){
var pdata = "";
var i=0;
this.state = 0;
this.xhttp.open("POST", purl, true);
this.SendHead();
if(this.keyCount!=-1 ){ //post数据
for(;i<=this.keyCount;i++){
if(pdata=="") pdata = this.keys[i]+'='+this.values[i];
else pdata += "&"+this.keys[i]+'='+this.values[i];
}
}
this.xhttp.send (pdata);
};
//用GET方式发送数据
this.SendGet = function(purl){
var gkey = "";
var i=0;
this.state = 0;
if(this.keyCount!=-1){ //get参数
for(;i<=this.keyCount;i++){
if(gkey=="") gkey = this.keys[i]+'='+this.values[i];
else gkey += "&"+this.keys[i]+'='+this.values[i];
}
if(purl.indexOf('?')==-1) purl = purl + '?' + gkey;
else purl = purl + '&' + gkey;
}
this.xhttp.open("GET",purl,true);
this.SendHead();
this.xhttp.send();
};
} // End Class DedeAjax
// Create XmlHttpRequest Object
function CreateXmlHttpRe(handler) {
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all && !is_op;
var thexmlhttp = null; if (is_ie) { // Guaranteed to be ie5 or ie6
var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
try {
thexmlhttp = new ActiveXObject(control);
thexmlhttp.onreadystatechange = handler;
} catch (ex) {
// TODO: better help message
alert("You need to enable active scripting and activeX controls");
}
} else {
// Mozilla,firefox
thexmlhttp = new XMLHttpRequest();
thexmlhttp.onload = handler;
thexmlhttp.onerror = handler;
}
return thexmlhttp;
};
// Get document Elemnet
function getElement(name) {
if (document.all) {
return document.all(name);
}
return document.getElementById(name);
}