I'm trying to load the contents of a modal from a remote page.
This is the code that I am using to run the tests.
$('[data-load-remote]').on('click', function (e) {
e.preventDefault();
var $this = $(this);
var remote = $this.data('load-remote');
if (remote) {
$($this.data('remote-target')).load(remote);
}
});
.modal-edit-buttom {
float: right;
font-size: 18px;
margin-right: 5px;
padding: 0;
cursor: pointer;
background: 0 0;
border: 0;
color: #000;
text-shadow: 0 1px 0 #fff;
opacity: .2;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap.min.css">
<button type="button" class="btn btn-primary" data-toggle="modal" data-load-remote="http://fiddle.jshell.net/vafleite/c5dLg852/3/show/" data-remote-target="#myModal" data-target="#myModal">Remote modal button</button>
<div class="modal hide" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">...</h3>
</div>
<div class="modal-body">
<p>...</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
And the modal that is loaded is this
<div class="modal-dialog" role="document">
<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>
<button type="button" class="modal-edit-buttom"> <span data-load-remote="http://fiddle.jshell.net/vafleite/62m9h069/1/show/" data-remote-target="#myModal" data-target="#myModal" class="glyphicon glyphicon-edit" aria-hidden="true">Edit</span>
</button>
<h4 class="modal-title" id="myModalLabel">Header test</h4>
</div>
<div class="modal-body">Body test</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>
I can load the remote modal using the load
method of jQuery, the content I'm loading is a complete modal (I've already seen some examples loading only modal-body, but I was not able to work with them either), in the header I put a button (Edit) that should (re) load the same modal but with other content, but apparently the jQuery function is not even called when I click this button.
I do not know if I could explain it well, but by the code I believe that you can better understand the idea ...