I have a problem, I cannot pass any parameters to a modal window (using Bootstrap 3), I tried using the solution stated in this link, but I cannot make it work:
Dynamically load information to Twitter Bootstrap modal
(Solution kexxcream user).
But pressing the button, the display does not show me anything, apparently blocks, attached a picture below:
http://i.imgur.com/uzRUyf1.png
I have attached the code (same code post above left);
HTML Code:
<div id="myModal" class="modal hide fade">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Title</h3>
</div>
<div class="modal-body">
<div id="modalContent" style="display:none;">
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-info" data-dismiss="modal" >Close</a>
</div>
</div>
JS Code:
$("a[data-toggle=modal]").click(function()
{
var essay_id = $(this).attr('id');
$.ajax({
cache: false,
type: 'POST',
url: 'backend.php',
data: 'EID='+essay_id,
success: function(data)
{
$('#myModal').show();
$('#modalContent').show().html(data);
}
});
});
Button:
<a href='#myModal' data-toggle='modal' id='2'> Edit </a>
PHP Code (backend.php):
<?php
$editId = $_POST['EID'];
?>
<div class="jumbotron">
<div class="container">
<h1>The ID Selected is <?php echo $editId ?></h1>
</div>
</div>
I found the solution at: Passing data to a bootstrap modal
So simply use:
with '
book-id
' is a attribute of modal with pre-fix 'data-
'I have found this better way , no need to remove data , just call the source of the remote content each time
There is a better solution than the accepted answer, specifically using data-* attributes. Setting the id to 1 will cause you issues if any other element on the page has id=1. Instead, you can do:
First of all you should fix modal HTML structure. Now it's not correct, you don't need class
.hide
:Then links should point to this modal via
data-target
attribute:Finally Js part becomes very simple:
Demo: http://plnkr.co/edit/4XnLTZ557qMegqRmWVwU?p=preview