ajax可能会向后台发送多个请求,因为不知道它们个别都什么时候完成,所以不知道是不是页面确实数据已经加载完毕,想知道最后一个请求时什么时候完成的。现在我用了代理去替换httpxmlrequest这个对象,并将这段代码注入到网页里,但问题是不知道页面什么时候数据加载完成
解决方案 »
- 测试想转j2EE和FLEX上的纠结,希望各位进来拍砖
- js大赛——求一份优美的代码
- 求一个制作XP开始菜单的实例,多级的向上显示菜单!
- 脚本截取一段字符串,提示 请实现properpies()
- 不显示删除回复显示所有回复显示星级回复显示得分回复 关于onmouseover显示onmouseout隐藏的问题,高分求助。
- 如何实现当鼠标移动到菜单上面,其背景色会随之改变并且标题栏下面自动显示与该标题相关的文字链接
- [分享]JavaScript获取元素在浏览器画布中的绝对位置
- jquery 多个对象如何绑定同一事件?
- 请问可否更改脚本弹出框中的字体??
- 在vbscript中如何获得当前日期的前一天
- div浮动层当滑动到底部时不再随滚动条滑动怎样控制呢
- 在js前端生成的图片可以直接变为pdf导出么?
xmlHttpRequest.readystate==4 表示完成
this.xmlHttpRequest = null; //保存XMLHttpRequest请求对象 var objXMLHttp;
if (window.XMLHttpRequest) {
objXMLHttp = new XMLHttpRequest();
this.xmlHttpRequest = createXMLHttpRequestAgent(objXMLHttp);
}
}//构造过程拦截
function createXMLHttpRequestAgent(ao) {
document.write(" 构造过程拦截start ");
var count=0;
var agent = new Object;
agent.xmlHttpRequest = ao; //被包裹的内核,是真正的通信对象
agent.syncAttribute = function () { //syncAttribute是用来同步属性的
try {
this.readyState = this.xmlHttpRequest.readyState;
this.responseText = this.xmlHttpRequest.responseText;
this.responseXML = this.xmlHttpRequest.responseXML;
this.status = this.xmlHttpRequest.status;//服务器状态
this.statusText = this.xmlHttpRequest.statusText;//http状态的对应文本
//this.onreadystatechange = this.xmlHttpRequest.onreadystatechange;
} catch (e) { }
};
agent.trigStateChange = function () { //模拟onreadystatechange
agent.syncAttribute();
switch (this.readyState) {
case 0:
document.write("未初始化! ");
break;
case 1:
count++;
document.write("开始向服务器发送请求,载入! ");
break;
case 2:
document.write("载入完成! ");
break;
case 3:
document.write("交互,正在解析响应内容! ");
break;
case 4:
if (this.status == 200) {
count--;
if (count == 0) { alert("all complete!"); }
document.write("与服务器交互完成调用! ");
}
break;
default:
alert("出界");
break;
}
if (agent.onreadystatechange != null) {
agent.onreadystatechange();
}
};
agent.xmlHttpRequest.onreadystatechange = agent.trigStateChange;
agent.abort = function () { //模拟abort
this.xmlHttpRequest.abort();
this.syncAttribute();
};
agent.getAllResponseHeaders = function () { //模拟内核对应的方法
var result = this.xmlHttpRequest.getAllResponseHeaders();
this.syncAttribute();
return result;
};
agent.getResponseHeader = function (headerLabel) { //模拟内核对应的方法
var result = this.xmlHttpRequest.getResponseHeader(headerLabel);
this.syncAttribute();
return result;
};
agent.open = function (method, url, asyncFlag, userName, password) {
this.xmlHttpRequest.open(method, url, asyncFlag, userName, password);
this.syncAttribute();
};
agent.send = function (content) { //模拟内核对应的方法
this.xmlHttpRequest.send(content);
this.syncAttribute();
};
agent.setRequestHeader = function (label, value) { //模拟内核对应的方法
this.xmlHttpRequest.setRequestHeader(label, value);
this.syncAttribute();
};
document.write(" 构造过程拦截end ");
return agent;
}代理是怎么写的,计数器写在哪合适呢?我的写法合适吗
这样就都完成了、、、