我试图让我的引导模态检索数据使用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">×</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
我究竟做错了什么?
解决方法
最高的投票答案是
deprecated in Bootstrap 3.3 and will be removed in 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(基于the official example.请注意,对于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">×</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>