ブートストラップモーダルでAjaxを使用してコンテンツをロードする 質問する

ブートストラップモーダルでAjaxを使用してコンテンツをロードする 質問する

私は、ブートストラップ モーダルで Ajax を使用してデータを取得しようとしています。

<a href="{{ path('ajax_get_messages', { 'superCategoryID': 35, 'sex': sex }) }}" data-toggle="modal" data-target="#birthday-modal">
  <img src="{{ asset('bundles/yopyourownpoet/images/messageCategories/BirthdaysAnniversaries.png') }}" alt="Birthdays" height="120" width="109"/>
</a>

私のモーダル:

<div id="birthday-modal" class="modal hide fade">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Birthdays and Anniversaries</h3>
</div>
<div class="modal-body">

</div>
<div class="modal-footer">
    <a href="#" data-dismiss="modal" class="btn">Close</a>
    {#<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>#}
</div>
</div>

リンクをクリックすると、モーダルは表示されますが、本文は空です。また、Ajax リクエストが行われているのも見えません。私は Bootstrap 2.1.1 を使用しています。

何が間違っているのでしょうか?

ベストアンサー1

最も投票数が多かった回答はBootstrap 3.3 では非推奨となり、v4 では削除される予定です。代わりにこれを試してください:

JavaScript:

// Fill modal with content from link href
$("#myModal").on("show.bs.modal", function(e) {
    var link = $(e.relatedTarget);
    $(this).find(".modal-body").load(link.attr("href"));
});

HTML(ベース公式の例Bootstrap 3.* では、data-remote="false"非推奨の Bootstrap ロード関数を無効にするように設定されていることに注意してください):

<!-- Link trigger modal -->
<a href="remoteContent.html" data-remote="false" data-toggle="modal" data-target="#myModal" class="btn btn-default">
    Launch Modal
</a>

<!-- Default bootstrap modal example -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

自分で試してみてください:https://jsfiddle.net/ednon5d1/

おすすめ記事