$(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;
});
問題は、ajaxでコンテンツをロードした後にjavascriptsコードをロードする必要があるため、jQueryのajax()メソッドなどのAjaxコールバックメソッドを使用して、リクエストの終了時に実行するものを定義するにはどうすればよいですか?
この関数を追加するのはどうですか?
$.ajax({
type: "POST",
url: "product.php",
dataType: "html",
success: function(msg){
if(parseInt(msg)!=0)
{
$('Conten').html(msg);
$('#loading').css('visibility','hidden');
}
}
});