问题
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