javascript - Firefox 3.0 中的无限刷新循环

标签 javascript jquery ajax firefox xmlhttprequest

我在 Firefox 3.0.x 中的 Javascript 遇到了一个奇怪的问题。在 Firefox 3.0.12 中,一旦加载列表正文,页面就会不断重新加载。 Firefox 3.5、Safari 4 和 Chrome 5(均在 Mac 上)都不会遇到此问题。

编辑:我创建了一个独立的示例,而不是从现有代码中提取它。

该问题与 FF 3.0 中将 location.hash 设置为空字符串时导致页面重新加载的错误有关。

test.js

function welcomeIndexOnLoad() {
  $("#options a").live('click', function () {
    optionClicked($(this), "get_list_body.html");
    return false;
  });

  $(document).ready(function() {
    optionClicked(null, "get_list_body.html");
  });
}

function optionClicked(sender, URL) {
  queryString = "";
  if (sender != null) {
    queryString = $(sender).attr("rel");
  }
  $("#list_body").load(URL + "?" + queryString, function(resp, status, AJAXReq) {
    console.log(resp);
    console.log("" + status);
    location.hash = queryString;
  });
}​

test.html

<html>
<head>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
  <script type="text/javascript" src="test.js"></script>
  <script>
    welcomeIndexOnLoad();
  </script>
</head>

<body>
<div id="container">
  Outside of list body.
  <div id="list_body">
  </div>
</div>
</body>
</html>

get_list_body.html

<h3>
  <div id="options">
    <a href="#" rel="change_list">Change List</a>
  </div>
<ul>
  <li>li</li>
</ul>

页面重新加载后,jQuery 第 5252 行(xhr.send() 调用)就会显示在控制台中:

xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );

最佳答案

经过更多搜索,我发现了这个 blog post ,其中提到在 Firefox 3.0 中将位置哈希设置为空字符串会导致页面刷新。

将我的默认查询字符串更改为“#”而不是空字符串可以解决问题。

关于javascript - Firefox 3.0 中的无限刷新循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2910198/

相关文章:

javascript - 将 AngularJs Widget 集成到 Adob​​e Captivate 中

javascript - 以 Angular 呈现表中数据的最佳方法

javascript - Webpack - CommonsChunkPlugin(lib 构建),common.js 未在父应用程序中加载

php - 将 CSS 应用于 Iframe 内容

javascript - Jquery 可拖动的内向外包含

javascript - 嵌套 div 中的 Ajax 调用不适用于带有 MVC3 的 FireFox

javascript - 网站如何使用 AJAX 即时更新其内容?

javascript - 当我构建 npm 时,我不断收到 builder.rimraf is not a function

javascript - jQuery 的链管

ajax - Django - Ajax 模式登录/注册