Class selectpicker Bootstrap, does not recognize option insertion via jquery (.html ())

0

I'm using Bootstrap framework, and the Selectpicker class to get the city data as state. The script works fine, it returns data, but instead of entering <option> Cidade X </option> it only inserts Cidade X . I know the problem is in the class, but I do not know how to solve it. Class:

<div class="col-md-3  col-xs-4" id="cidade">

<select data-width="auto" id="municipio" name="municipio" class="selectpicker municipio">
    <option value="0" disabled="disabled">Selecione o estado</option>
</select>
</div>

Script:

    $(document).ready(function(){

    $("#estado").change(function() {

        var est = document.getElementById("estado").value; 

        debugger;

        $.ajax({
        type: 'post',
         url: 'cidade.php',
         data: {
          cd_estado: est
         },
         success: function(dados) {
            $(".municipio").html(dados);
         }
         });

    });
});
    
asked by anonymous 22.02.2017 / 23:01

1 answer

0

When you use .html () you override the select element, assuming you are ajaxing the options in that select, use the append () function to add child elements in the select.

Edit: Bring the mounted element of your controler, that is, bring it inside the "option" tags.

    
27.02.2017 / 04:59