+ -
当前位置:首页 → 问答吧 → firefox4 ajax(异步)请求后立即使用Window.location.href跳转,ajax请求没有发出

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;
}

作者: 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);

作者: toury   发布时间: 2011-05-25

这个我知道。不过我就是想知道它在跳转时是怎么处理的?(最好是官方的)

作者: wuhy009   发布时间: 2011-05-25