我使用jQuery 1.4与jQuery历史,并试图找出为什么萤火虫/ Web Inspector是显示访问我的网站主页(/
或/#
)时,在每个页面加载(双倍金额2个XHR GET请求。为什么jQuery .load()会触发两次?
如访问this(或)使用Firebug页面启用
以下是编辑/相关代码(见full source): - 。
$(document).ready(function() {
$('body').delegate('a', 'click', function(e) {
var hash = this.href;
if (hash.indexOf(window.location.hostname) > 0) { /* Internal */
hash = hash.substr((window.location.protocol+'//'+window.location.host+'/').length);
$.historyLoad(hash); return false;
} else if (hash.indexOf(window.location.hostname) == -1) { /* External */
window.open(hash); return false;
} else { /* Nothing to do */ }
});
$.historyInit(function(hash) {
$('#loading').remove(); $('#container').append('<span id="loading">Loading...</span>');
$('#ajax').animate({height: 'hide'}, 'fast', 'swing', function() {
$('#page').empty(); $('#loading').fadeIn('fast');
if (hash == '') { /* Index */
$('#ajax').load('/ #ajax','', function() { ajaxLoad(); });
} else {
$('#ajax').load(hash + ' #ajax', '', function(responseText, textStatus, XMLHttpRequest) {
switch (XMLHttpRequest.status) {
case 200: ajaxLoad(); break;
case 404: $('#ajax').load('/404 #ajax','', ajaxLoad); break; // Default 404
default: alert('We\'re experiencing technical difficulties. Try refreshing.'); break;
}
});
}
}); // $('#ajax')
}); // historyInit()
function ajaxLoad() {
$('#loading').fadeOut('fast', function() {
$(this).remove(); $('#ajax').animate({height: 'show', opacity: '1'}, 'fast', 'swing');
});
}
});
的几个注意事项,可能会有所帮助: -
- 使用WordPress的默认/标准的.htaccess
- 我通过只有JavaScript(PE)重定向到
/links-like/this
/#links-like/this
- 我实现以上
window.location.replace(addr);
而不是window.location=addr;
- 我实现以上
- 如有需要,请随时访问my site。
在此先感谢。
不,试过了。我在页面头部以纯JS显示如下: - '' 注释掉'window.location.replace(g);'仍然有同样的效果。还有其他建议吗? 无论如何感谢保罗。 – LeslieOA 2010-03-13 10:36:40