Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Loading Content in Bootstrap 4 Modal Body via Ajax</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script> <script> $(document).ready(function(){ $("#myModal").on("show.bs.modal", function(event){ // Place the returned HTML into the selected element $(this).find(".modal-body").load("/examples/php/remote.php"); }); }); </script> <style> .bs-example{ margin: 20px; } </style> </head> <body> <div class="bs-example"> <!-- Button HTML (to Trigger Modal) --> <button type="button" class="btn btn-lg btn-primary" data-toggle="modal" data-target="#myModal">Launch Demo Modal</button> <!-- Modal HTML --> <div id="myModal" class="modal fade" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Ajax Loading Demo</h5> <button type="button" class="close" data-dismiss="modal">×</button> </div> <div class="modal-body"> <!-- Content will be loaded here from "remote.php" file --> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">OK, Got it!</button> </div> </div> </div> </div> </div> </body> </html>