我在 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/