passing a parameter to remote modal in bootstrap 3

馋奶兔 提交于 2019-12-13 19:38:13

问题


I have a function to load remote content into a bootstrap 3 modal, which uses the id from a php generated recordset. I seem to be retrieving the id correctly, but the remote page content always shows the first id i clicked on

<script type="text/javascript">
$(document).ready(function(){
    $('.pull-right').click(function(){
        var id = this.id;
        alert(id);
        $('#myModal').modal({

    remote: '/member_profile.php?MemberID='+id,
    show: true
});
    }); 
});
</script>

As the id is being generated correctly, is the parameter not being passed to the remote php page correctly ?


回答1:


You need to reset the data any time you open an AJAX modal. This is what you're looking for:

$('body').on('hidden.bs.modal', '#myModal', function() { $(this).removeData('bs.modal'); });




回答2:


$('#myModal').on('hide.bs.modal', function(){
   $(this).removeData('bs.modal');
});

Yes, "hide" not "hidden" if you did not disable the Modal animation by default. This will perform more stable and solid since it fires right after you dismiss the modal div. I just do this way after a really nightmare...

And I found that removeData('bs.modal') has already been added into the Bootstrap 3.1 source code, but just on event 'hidden.bs.modal', so sometimes the bug still happens.



来源:https://stackoverflow.com/questions/21457365/passing-a-parameter-to-remote-modal-in-bootstrap-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!