に動作していない私は、Ajaxを介してコンテンツをロードしています、DIVの中で、私が3ページ必要があります:アヤックス javascript.jsを介してロードジャバスクリプトを動的にロードされたコンテンツ
インデックス 動的なコンテンツを
今、私は、インデックスにデータをロードする際に経由:javascriptのは、私がメインインデックス上のJavaScriptファイルを含めていたとしても、それは動作しません
$.ajax({
url: target,
type: 'GET',
}).done(function(data)
{
$(".modal-content").html($(data).find('.inner_modal'));
$(".modal-header").prepend('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>');
});
});
。
私はそうのように結合しようとしている:私はそうのようにそれを試してみました
$(function()
{
$('.inner_modal').on("submit", "#account-login-form", function()
{
$('.ajloading').show();
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
dataType: 'json',
data: $(this).serialize(),
success: function(data)
{
if(!data.success)
{
$('#error_message').html(data.error + alert_close).show();
}else{
<?php if(Session::get('refer') == true && Session::get('refer') != 'user/logout'): ?>
window.location.href = '<?php echo Config::get('URL'); ?><?php echo System::escape(Session::get('refer')); ?>';
<?php else: ?>
window.location.href = '<?php echo Config::get('URL'); ?>dashboard';
<?php endif; ?>
}
$('.ajloading').hide();
}, error: function(data)
{
$('.ajloading').hide();
}
});
return false;
});
});
:
$(document).on("submit", "#account-login-form", function()
私はuncludeたときに私も今
せずにそれを試してみましたjavscriptファイルは動的に読み込まれたコンテンツの中で動作しますが、私はそれをすべてのファイルに対して行うことはできません。さらに、私のscriを膨らませるでしょうPTので、どのように私はこの問題を解決することができますので、動的なコンテンツが私のメインのjsファイルで動作します....ここで私はそれを行う方法は次のとおりです。
<body>
<div class="modal-content">
<!-- dynamic content loaded !-->
</div>
</body>
<script>
$.ajax({
url: target,
type: 'GET',
}).done(function(data)
{
$(".modal-content").html($(data).find('.inner_modal'));
$(".modal-header").prepend('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>');
});
});
</script>
<script src="myjs.js"></script>
</html>
「作業していない」とはどういう意味ですか - ページに表示されるコードであり、「発射」しないコードですか?ページに表示されません。コンソールに何かエラーがありますか?また、前のこの回答をチェックアウト:http://stackoverflow.com/questions/3619484/can-i-add-javascript-dynamically-to-an-existing-script-element –
あなたのスクリプトの '' defering'はどうですか? [async vs defer](http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html) – Anthony
@timsterそれは発砲していませんが、それは私のメインスクリプトのフッターにあります。コンソールエラーは発生しません。 –