Copy Code code as follows:
var ajax = {
Init:function () {
var xmlHttp = new XMLHttpRequest ();
if (!window. XMLHttpRequest)
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
return xmlHttp;
},
Call:function (opt) {
var xmlHttp = This.init ();
Xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate===4)
{
Xmlhttp.status===200?
Opt.success (Xmlhttp.responsetext,xmlhttp.responsexml): Opt.error (Xmlhttp.responsetext,xmlhttp.status);
}
}
Opt.data = This.parsedata (Opt.data);
if (opt.method.toLowerCase () = = = ' Get ') {
Opt.url = Opt.url + "?" + Opt.data;
Opt.data = null;
}
Xmlhttp.open (Opt.method,opt.url,opt.async);
if (opt.method.toLowerCase () = = ' Post ')
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send (Opt.data);
},
Parsedata:function (data) {
if (typeof data = = ' object ') {
var str = ';
for (var i in data) {
STR + + "&" +i+ "=" +encodeuricomponent (Data[i]);
}
Return str.length==0? Str:str.substring (1);
}else{
return data;
}
}
}