jqueryajaxmodal-dialogtwitter-bootstrap-3

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.


Solution

  • 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') });
            });