如何向此腳本添加AJAX回調函數?向此腳本添加AJAX回調函數
此腳本正在使用AJAX加載內容,但不刷新頁面頁面,但它不加載腳本。我想如果我添加回調函數,腳本將加載。
$(document).ready(function() {
var hash = window.location.hash.substr(1);
var href = $('#nav li a').each(function() {
var href = $(this).attr('href');
if (hash == href.substr(0, href.length - 5)) {
var toLoad = hash + '.php #conten';
$('#conten').load(toLoad)
}
});
$('#nav li a').click(function() {
var toLoad = $(this).attr('href') + ' #conten';
$('#conten').hide('fast', loadContent);
$('#load').remove();
$('#conten').append('<span id="load"></span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0, $(this).attr('href').length - 5);
function loadContent() {
$('#conten').load(toLoad, '', showNewContent)
}
function showNewContent() {
$('#conten').show('normal', hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
});
你認爲腳本沒有加載,因爲load()....所以我應該改變這個代碼? –
這是一個負載的有效用法:http://api.jquery.com/load/#loading-page-fragments – cjc343
thnx這麼多人的問題因爲spaaaaaaace:D –