我写的一个XMLHTTPREQUEST的类,作为本人在AJAX的第一帖吧

kangqin 2006-02-28 01:18:28
xmlhttprequest.js:

function request(onerror)
{
this.xmlhttpObj=null;
this.onError=onerror?onerror:this.defaultOnError;
this.isIE=navigator.appName.indexOf("Microsoft")!=-1?true:false;
if(this.isIE)
{
try{
this.xmlhttpObj=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
this.xmlhttpObj=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
this.onError.call(this,e);
}
}
}
else
{
this.xmlhttpObj=new XMLHttpRequest();
if(this.xmlhttpObj.overrideMimeType)
{
this.xmlhttpObj.overrideMimeType("text/xml");
}
}
}

request.prototype={

defaultOnError:function(error)
{
if(navigator.appName.indexOf("Microsoft")!=-1)
alert(error.message);
else
alert(error);
},

open:function(url,method,callback,params,headers)
{
var tempObj=this.xmlhttpObj;
var errorCall=this.onError;
var isIE=this.isIE;
method=method=="POST"?"POST":"GET";
try{
if(!tempObj)
throw (isIE?new Error(null,"请先建立连接。"):"请先建立连接。");
else
{
try{
tempObj.open(method,url,true);
if(headers)
{
for(var key in headers)
tempObj.setRequestHeader(key,headers[key]);
}
tempObj.send(params?params:null);
tempObj.onreadystatechange=function()
{
try{
if(tempObj.readyState==4&&tempObj.status==200&&callback)
{
callback.call(this,tempObj);
}
else if(tempObj.readyState==4&&tempObj.status!=200)
{
throw (isIE?new Error(null,"网页请求失败了,返回状态:"+tempObj.status):"网页请求失败了,返回状态:"+tempObj.status);
}
}catch(e){
errorCall.call(tempObj,e);
}
}
}catch(e){
throw e;
}
}
}catch(e){
this.onError.call(this,e);
}
}
}

使用范例:
<script type="text/javascript" src="xmlhttpclass.js"></script>
<script type="text/javascript">
var obj=new request();
obj.open("http://www1.5460.net","POST",function);
</script>
...全文
675 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
NIDEDIYI1027 2006-06-19
  • 打赏
  • 举报
回复
顶一下!
wfz131 2006-06-18
  • 打赏
  • 举报
回复
顶呀
yincj 2006-06-01
  • 打赏
  • 举报
回复
不错。
学学!!!
Go_Rush 2006-05-31
  • 打赏
  • 举报
回复
写得不错的
Go_Rush 2006-05-31
  • 打赏
  • 举报
回复
up
ljlyy 2006-05-31
  • 打赏
  • 举报
回复
看看先!!
Scarroot 2006-05-25
  • 打赏
  • 举报
回复
mark
chouchy 2006-05-16
  • 打赏
  • 举报
回复
mark
pswdf 2006-03-13
  • 打赏
  • 举报
回复
强烈支持!
mingxuan3000 2006-03-11
  • 打赏
  • 举报
回复
make
ljlyy 2006-03-11
  • 打赏
  • 举报
回复
支持一下
shao0408 2006-03-10
  • 打赏
  • 举报
回复
Mark
cansum396 2006-03-09
  • 打赏
  • 举报
回复
make
超级大笨狼 2006-03-02
  • 打赏
  • 举报
回复
Ajax.Net现在的最新版本是AjaxPro5.11.4.2,

下载地址是:www.schwarz-interactive.de

AJAX.NET可以在VS2005或者VS.NET2003下使用。

又增加了些例子和小电影
superdullwolf.cnzone.net/ajax.rar

6个ASP.net C#实现和1个ASP实现 ajax例子 打包下载



ioul 2006-03-01
  • 打赏
  • 举报
回复
支持
bocheny 2006-02-28
  • 打赏
  • 举报
回复
谢谢
sWinZ 2006-02-28
  • 打赏
  • 举报
回复
支持
mynamesucks 2006-02-28
  • 打赏
  • 举报
回复
支持楼主,我就没这个耐心了,直接拿其他现成的用了
feandy 2006-02-28
  • 打赏
  • 举报
回复
UP
iamhejianke 2006-02-28
  • 打赏
  • 举报
回复
顶一下
加载更多回复(3)

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧