简体   繁体   中英

jquery destroy modal dialog on close

I have a jquery modal dialog which is created as follows in a function:

function EditDialog(pk) {            
        $.ajax({
            url: "{% url 'populatereviewform' %}",
            method: 'GET',
            data: {
            pk: pk
        },
        success: function(formHtml){
            //place the populated form HTML in the modal body
            $('.modal-body').html(formHtml);
            $( "#dialog" ).modal({width: 500, height: 500});
        },
        dataType: 'html'
        });
    return false;
}

How can I ensure that every time I call this function a fresh instance of the dialog is created? I wonder if somehow I can hook into the close event and ensure that the dialog is completely destroyed. I am trying to debug something and it seems that some of my variables do not get refreshed when this dialog is called a second time and I am trying to get to the bottom of it. The django template for creating the dialog is:

 <div id="dialog" class="modal" title="Edit" style="display:none">
        <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Review Uploaded Image</h4>
              </div>
              <div class="modal-body">
              </div>
          </div>
        </div>
    </div>

You can use the bootstrap modal callback.

$('#dialog').on('hidden.bs.modal', function () {
  $('.modal-body').html('');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM