javascriptjqueryajaxtwitter-bootstrap

How do I close a modal window after AJAX success


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:

<button data-toggle="modal" data-target="#CompanyProfile"data-backdrop="static" data-keyboard="false">Click </button>

How do I close this modal after $.ajax success using jQuery?

I have done a few tests - the modal has closed but the background gets locked, and I cannot do anything until I refresh the page


Solution

  • To close bootstrap modal you can pass 'hide' as option to modal method as follows.

    $('#CompanyProfile').modal('hide');
    

    Use this code inside ajax success.

    Fiddle Demo