jQuery History で jQuery 1.4 を使用しており、ページの読み込みごとに Firebug/Web Inspector が 2 つの XHR GET リクエストを表示している理由を理解しようとしています (サイトのホームページにアクセスすると、その量が 2 倍になります (/
または/#
)。
例: Firebug を有効にして、この(または任意の) ページにアクセスします。
編集された/関連するコードは次のとおりです (完全なソースを参照してください): -
$(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');
});
}
});
役立つかもしれないいくつかのメモ: -
- デフォルト/標準の .htaccess で WordPress を使用する
- JavaScriptのみを介してリダイレクト
/links-like/this
し/#links-like/this
ています(PE)- 私は上記を達成して
window.location.replace(addr);
いますwindow.location=addr;
- 私は上記を達成して
- 必要に応じて、私のサイトにアクセスしてください。
前もって感謝します。