關於AJAX類代碼

基本用法:

關於AJAX類代碼

複製代碼 代碼如下:

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);

};

};