As some other Bootstrap answers and documents show, Bootstrap 4 requires the handling of the show.bs.modal event to load content into a modal one. You can use this to load content from an HTML string or from a remote URL. Here is a working example ...
$('#theModal').on('show.bs.modal', function (e) { var button = $(e.relatedTarget); var modal = $(this); // load content from HTML string //modal.find('.modal-body').html("Nice modal body baby..."); // or, load content from value of data-remote url modal.find('.modal-body').load(button.data("remote")); });
Bootstrap 4 Remote URL Demo
Another option is to open the modal as soon as the data is returned from the Ajax call ...
$.ajax({ url: "http://someapiurl", dataType: 'json', success: function(res) { // get the ajax response data var data = res.body; // update modal content $('.modal-body').text(data.someval); // show modal $('#myModal').modal('show'); }, error:function(request, status, error) { console.log("ajax call went wrong:" + request.responseText); } });
Bootstrap 4 Download Modal from Ajax Demo
source share