Last active
March 23, 2018 15:02
-
-
Save gaulatti/fa0661d62728ca967ae1 to your computer and use it in GitHub Desktop.
Dynamic (AJAX) Bootstrap Modal (Bootstrap 3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("[data-toggle='modal']").click(function(e) { | |
/* Prevent Default*/ | |
e.preventDefault(); | |
/* Parameters */ | |
var url = $(this).attr('href'); | |
var container = "#" + $(this).attr('data-container'); | |
/* XHR */ | |
$.get(url).done(function(data) { | |
$(container).html(data).modal(); | |
}).success(function() { $('input:text:visible:first').focus() }); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- JS --> | |
<script src="caller.js"></script> | |
<!-- Link --> | |
<a href="/url/to/modal.html" data-toggle="modal" data-container='modal-container'>Abrir Modal</a> | |
<!-- Buenos Modales --> | |
<div id="modal-container"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<a class="close" data-dismiss="modal">×</a> | |
<h3>Title</h3> | |
</div> | |
<div class="modal-body"> | |
<p>Content</p> | |
</div> | |
<div class="modal-footer"> | |
<a class="btn btn-primary" onclick="$('.modal-body > form').submit();">Save Changes</a> | |
<a class="btn" data-dismiss="modal">Close</a> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment