jsp案例分析(二)-聊天室-3-代码分析
来源:互联网 发布:软件结构设计 编辑:程序博客网 时间:2024/05/18 03:24
包括myeclipse工程的源代码:
http://download.csdn.net/detail/flyuniverse_shell/4144288
本程序可以熟悉ajax,请看如下代码:
var net=new Object(); //定义一个全局变量net
net.AjaxRequest=function(url,onload,onerror,method,params){//创建一个构造函数
this.req=null;
this.onload=onload;
this.onerror=(onerror) ? onerror : this.defaultError;
this.loadDate(url,method,params);
}
net.AjaxRequest.prototype.loadDate=function(url,method,params){
if (!method){
method="GET";
}
if (window.XMLHttpRequest){
this.req=new XMLHttpRequest();
} else if (window.ActiveXObject){
this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
if (this.req){
try{
var loader=this;
this.req.onreadystatechange=function(){
net.AjaxRequest.onReadyState.call(loader);
}
this.req.open(method,url,true);
//this.req.send(params);
this.req.send(null);
}catch (err){
this.onerror.call(this);
}
}
}
net.AjaxRequest.onReadyState=function(){ //重构onReadyState函数
var req=this.req;
var ready=req.readyState;
if (ready==4){
if (req.status==200 ){
this.onload.call(this);
}else{
this.onerror.call(this);
}
}
}
net.AjaxRequest.prototype.defaultError=function(){ //默认的错误处理函数
alert("error fetching data!"
+"\n\nreadyState:"+this.req.readyState
+"\nstatus: "+this.req.status
+"\nheaders: "+this.req.getAllResponseHeaders());
}
- jsp案例分析(二)-聊天室-3-代码分析
- jsp案例分析(二)-聊天室-1-部署、调试
- jsp案例分析(二)-聊天室-2-逆向建模
- hadoop案例分析(二)
- jsp案例分析(一)-在线投票系统-4-代码分析
- 基于Linux的消息队列及多线程编程实现的聊天室(二)代码分析
- 基于Linux的消息队列及多线程编程实现的聊天室(二)代码分析
- 聊天室的VC代码分析
- javaweb-jsp-PageContext对象分析及代码和截图案例
- 项目案例分析二
- 分析函数案例二
- MBA案例分析(人员培训二)
- unity shader案例分析(二)
- lvm代码分析(二)
- IpMsg代码分析(二)
- libjingle代码分析(二)
- JM代码分析(二)
- Hive日志分析案例二
- CStdioFile类输出中文字
- 如何在IIS中发布silverlight+WCF项目
- 顺时针,逆时针,zigzag矩阵详解
- win7便签的cheat sheet
- C++代码点滴
- jsp案例分析(二)-聊天室-3-代码分析
- 关于脚本
- 云计算架构基础之多租户数据架构 (一) 三种模式和影响选择的因素
- 云计算架构基础之多租户数据架构 (二) 三种模式实现相关的一些模式
- eclipse,myeclipse中java连接数据库的问题
- seo 初体验
- 设计模式学习笔记(四)之工厂模式(Factory)
- C#索引器
- 十大网站盈利方式