How do I close a modal window after AJAX success

前端 未结 6 1045
梦如初夏
梦如初夏 2020-12-17 14:19

I have a button which opens a modal but I have prevented the modal close by clicking background or ESC key.

My button looks like this:

6条回答
  •  被撕碎了的回忆
    2020-12-17 15:09

    I define my modal :

      
    

    then I use create function :

    var StopLoadingAnimation = function () {
    $('#modal').on('show.bs.modal', function (e) {
        console.log("trigger show");
        $("#btnCloseModal").trigger("click");
    });
    $('#modal').on('shown.bs.modal', function (e) {
        console.log("trigger");
        $("#btnCloseModal").trigger("click");
    });
    $('#modal').on('hidden.bs.modal', function (e) {
        console.log("event");
        $(e.currentTarget).off('shown');
        $(e.currentTarget).off('show');
    });
    $("#btnCloseModal").trigger("click");
    

    }

    My idea is after ajax success is will call function StopLoadingAnimation what will trigger event click on element btnCloseModal ( It like you click button btnCloseModal when you closing modal )

提交回复
热议问题