Search code examples
javascriptjquerymulti-selectbootstrap-multiselect

I need to recreate the multiselect after ajax response


I need to recreate the multiselect in "Local" after "Empresa" ajax response with this data response. I put the information in "Local" select but I am not able to recreate the "Local" multiselect.

$.ajax({
    url: '/ajaxrequests/requestlocals',
    type: 'POST', dataType: 'json',
    data: {empresas:empresas},
    success: function(retorno){
        console.log(retorno);
        $('#ajax_local').html("");
        $.each(retorno, function (valor, chave) {
            $('#ajax_local').append($('<option>', {
                value: valor,
                text : chave
            }));
        });
        $('#ajax_local').multiselect();
    }
});

Imagem 1 Imagem 2


Solution

  • Try to destroy it first;

    $("#ajax_local").multiselect('destroy');
    $("#ajax_local").multiselect();