基本用法:
复制代码 代码如下:
var ajax = new AjaxObj(url);
istener(200, function(r){
alert(r);
});
();
也可以连续调用:
复制代码 代码如下:
var ajax = new AjaxObj(url)istener(200, function(r){
alert(r);
})();
另外还支持自定义的`POST或GET方式请求,以及监视不同的HTTP状态码,自己看代码琢磨吧 :)
完整代码:
复制代码 代码如下:
AjaxObj = function(url, method, content){
this.r = null;
= url;
od = method;
ent = content;
er = {};
er["Connection"] = "close";
er["Content-type"] = "application/x-www-form-urlencoded";
var self = this;
if(ttpRequest){
this.r = new XMLHttpRequest();
}else if(veXObject){
try {
this.r = new ActiveXObject("TTP");
} catch(e) {
try{
this.r = new ActiveXObject("TTP");
} catch(e) {
}
}
}
istener = function(http_status, func){
if(!this.L)
this.L=[];
this.L[http_status] = func;
return this;
};
eader = function(name, value){
er[name] = value;
equestHeader(name, value);
return this;
};
= function(){
if(od != "post" && od != "get")
od = "get";
(od, , true);
for(var h in er) {
equestHeader(h, er[h]);
}
(ent);
};
if(this.r) adystatechange = function(){
if(yState == 4 && self.L[us] != null)
self.L[us](onseText);
};
};