首页 > 开发 > AJAX > 正文

AJAXRequest v0.2

2024-09-01 08:31:58
字体:
来源:转载
供稿:网友


/*------------------------------------------
Author: xujiwei
Website:
E-mail: vipxjw@163.com
Copyright (c) 2006, All Rights Reserved
------------------------------------------*/
function AJAXRequest(pmethod,purl,pasync,pcontent,pcallback) {
var xmlObj = false;
var CBfunc,ObjSelf;
ObjSelf=this;
try { xmlObj=new XMLHttpRequest; }
catch(e) {
try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
catch(e2) {
try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e3) { xmlObj=false; }
}
}
if (!xmlObj) return false;
this.method=pmethod;
this.url=purl;
this.async=pasync;
this.content=pcontent;
this.callback=pcallback;
this.send=function() {
if(!this.method||!this.url||!this.async) return false;
xmlObj.open (this.method, this.url, this.async);
if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlObj.onreadystatechange=function() {
if(xmlObj.readyState==4) {
if(xmlObj.status==200) {
ObjSelf.callback(xmlObj);
}
}
}
if(this.method=="POST") xmlObj.send(this.content);
else xmlObj.send(null);
}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表