Search code examples
javascriptjqueryajaxmulti-selectbootstrap-multiselect

Bootstrap multiselect open only the first time - After ajax it doesn't work


I try to use bootstrap multiselect with jquery ajax. When execute ajax the multi select button it doesn't work. You can see the problem here: http://www.doyleia.com/anazitisi-ergasias in the last multiselect.

ajax code:

function runAjax(tags, contracts, educations, towns) {

$(document).ajaxStart(function(){
    $("#wait").css("display", "block");
});
$(document).ajaxComplete(function(){
    $("#wait").css("display", "none");
});
$.ajax({
    url: 'http://www.doyleia.com/anazitisi-ergasias?' + tags + '&' + contracts + '&' + educations + '&' + towns,
}).done(function(data){
    // destroy I used it because builded again the multiselect button after ajax
    $('.multi-boot-select').multiselect('destroy');
    var $html = $(data);
    //hide within that object
    $html.find('.form-for-hide').hide();
    $html.find('p.hidden').removeClass('hidden');
    // insert the object
    $('div.load-jobs').html($html);
});

}


Solution

  • I have changed the ajax like bellow and now it works:

    function runAjax(tags, contracts, educations, towns) {
    
    $(document).ajaxStart(function(){
        $("#wait").css("display", "block");
    });
    $(document).ajaxComplete(function(){
        $("#wait").css("display", "none");
    });
    $.ajax({
        url: 'http://www.doyleia.com/anazitisi-ergasias?' + tags + '&' + contracts + '&' + educations + '&' + towns,
    }).done(function(data){
        // destroy I used it because builded again the multiselect button after ajax
        var $html = $(data);
        //hide within that object
    
        var finalGet =  $html.find('.row-to-take');
    
        //$html.find('.form-for-hide').hide();
        $html.find('.hidden.alert.alert-danger').removeClass('hidden');
    
        // insert the object
        $('div.load-jobs').html(finalGet);
    });
    

    }