bookthief bookthief - 1 year ago 230
Javascript Question

Bootstrap modal onload event

Does a bootstrap modal have an onload event? I want to call a http GET request when the modal is opened to populate the modal with data from a rest api. I have a form in the modal and I have called the GET function on the onload event of the form, but it doesn't work.

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Agent details:</h4>
<div class="modal-body">

<form onload="getData()" style= "font-size: 16pt">

Answer Source

Per the documentation, you can listen to the show or shown events.

From The Documentation: => This event fires immediately when the show instance method is called. => This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete).

$('#myModal').on('', function () {
  // do something…
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download