script in page loaded via AJAX doesn't execute in modal (BS4)

牧云@^-^@ 提交于 2019-12-11 12:08:15

问题


The following code successfully dynamically loads the "remote" page (data-remote="/booking-app-1") within the modal-body. However, this target page just contains a < script > which loads an IFrame (for an external payment application). This script does not execute. Is there a way to fix this, or a better way to just inject the booking applications's script via its URL directly into the modal-body? I've also tried swapping the data-remote URL to my page with the URL direct to the booking app's script but this did not work.

<button type="button" class="btn" data-toggle="modal" data-target="#bookingApp-1" data-remote="/booking-app-1" >
 BUY THING 1
</button>


<!-- Modal -->
<div class="modal fade" id="bookingApp-1" tabindex="-1" role="dialog" aria-labelledby="bookingApp-1" aria-hidden="true">
  <div class="modal-dialog" role="document">
      <div class="modal-body">
         (CONTENT LOADS HERE)
      </div>
  </div>
</div>



<script> // I will have multiple modals with different scripts on the page
$('body').on('click.modal.data-api',
      '[data-toggle="modal"]', function(){ 
         $($(this).data("target")+' .modal-body').load($(this).data('remote')); });
</script>

/booking-app.php:

<script type="text/javascript" src="https://bookeo.com/widget.js?a=12345&amp;type=1234_not_the_actual_url"></script>

来源:https://stackoverflow.com/questions/48812120/script-in-page-loaded-via-ajax-doesnt-execute-in-modal-bs4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!