0

I have a Bootstrap 3.3.7 modal (#calendarModal) being opened when an <a> tag is clicked:

<a style="display:block" href="#" data-toggle="modal" data-target="#calendarModal">

I want to make a jquery ajax request when the modal has opened.

I've taken a look at https://github.com/twbs/bootstrap/issues/5169 but binding won't work. For example the link suggests:

$('#calendarModal').bind('load', function() { /* do something cool */ });

That doesn't work. If I use console.log inside the function to test it, it doesn't seem to fire.

How can this be done? I realise I could target the click on the anchor but I'd prefer to know how to do it when the modal is loaded?

Andy
  • 5,142
  • 11
  • 58
  • 131
  • 3
    Possible duplicate of [Calling a function on bootstrap modal open](http://stackoverflow.com/questions/17461682/calling-a-function-on-bootstrap-modal-open) – ADyson Nov 25 '16 at 15:59
  • @ADyson agreed, the answer is within that post. `$('#calendarModal').on('shown.bs.modal', function (e) {` – Andy Nov 25 '16 at 16:03
  • 2
    Within the shown.bs.modal function, just put your ajax code there. – Stephen C Nov 25 '16 at 16:07

0 Answers0