firefox4 ajax(异步)请求后立即使用Window.location.href跳转,ajax请求没有发出
时间:2011-05-25
来源:互联网
firefox4 ajax(异步)请求后立即使用Window.location.href跳转,ajax请求没有发出。
这段代码在IE6,7,8,9和firefox4之前的版本都可以,就是firefox4不行。
用firefox的web控制台监视,只能看到页面跳转的请求。不知道是什么原因。
自己本人猜测是FireFox4在页面跳转时,如果有没有结束的请求,就会自动把这些
请求结束掉。但是因为没有找到官方说法,所以也不能确定就是这样。希望各位兄弟姐妹
帮帮忙!
代码如下:
function ajaxRequest(){
var xmlRequest;
if (window.XMLHttpRequest) {
xmlRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (window.XMLHttpRequest) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
}
xmlRequest.open("GET", Ajax请求的URL, true);
xmlRequest.onreadystatechange = function(){};
xmlRequest.send(null);
window.location.href=页面跳转的URL;
}
这段代码在IE6,7,8,9和firefox4之前的版本都可以,就是firefox4不行。
用firefox的web控制台监视,只能看到页面跳转的请求。不知道是什么原因。
自己本人猜测是FireFox4在页面跳转时,如果有没有结束的请求,就会自动把这些
请求结束掉。但是因为没有找到官方说法,所以也不能确定就是这样。希望各位兄弟姐妹
帮帮忙!
代码如下:
function ajaxRequest(){
var xmlRequest;
if (window.XMLHttpRequest) {
xmlRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (window.XMLHttpRequest) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
}
xmlRequest.open("GET", Ajax请求的URL, true);
xmlRequest.onreadystatechange = function(){};
xmlRequest.send(null);
window.location.href=页面跳转的URL;
}
作者: wuhy009 发布时间: 2011-05-25
你等它结束在跳转:
xmlRequest.open("GET", Ajax请求的URL, true);
xmlRequest.onreadystatechange = function(){
if(xmlRequest.readyState==4&&(xmlRequest.status==200||xmlRequest.status==0)){
window.location.href=页面跳转的URL;
}
};
xmlRequest.send(null);
xmlRequest.open("GET", Ajax请求的URL, true);
xmlRequest.onreadystatechange = function(){
if(xmlRequest.readyState==4&&(xmlRequest.status==200||xmlRequest.status==0)){
window.location.href=页面跳转的URL;
}
};
xmlRequest.send(null);
作者: toury 发布时间: 2011-05-25
这个我知道。不过我就是想知道它在跳转时是怎么处理的?(最好是官方的)
作者: wuhy009 发布时间: 2011-05-25
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28