Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing content cache from bootstrap modal

I'm using a dynamically generated list of links to show a modal window with ajax loaded content. Bootstrap automatically caches the content and doesn't clear it on modal hide event.

I need to get new content every time I click the link, how can I workaround this? I checked and there are no methods or properties to set the caching to false.

like image 350
thusithak Avatar asked Dec 02 '13 07:12

thusithak


2 Answers

You can use something like this:

        <a href="/my/url" class="modal-toggle">test</a>


        $('body').on('click', '.modal-toggle', function (event) {
            event.preventDefault();
            $('.modal-content').empty();
            $('#myModal')
                .removeData('bs.modal')
                .modal({remote: $(this).attr('href') });
        });
like image 81
Diego Plentz Avatar answered Oct 24 '22 18:10

Diego Plentz


this worked for me..

$('body').on('hidden.bs.modal', '.modal', function () {
        $(this).removeData('bs.modal');
      });
like image 20
Indhi Avatar answered Oct 24 '22 18:10

Indhi