Issue on Loading Bootstrap Select Options Through Ajax Post

[亡魂溺海] 提交于 2019-12-10 17:00:05

问题


Using Bootstrap 3 and Bootstrap-Select plugin I am trying to load the options of the select drop down by ajax from database.the code works perfectly when I remove the select picker lass from the select element but with that class (which is required to use bootstrap select) it is not loading any of options.

 <select id="arearesults" class="selectpicker" data-live-search="true">
    <option value="select">Select From The List</option>
 </select>

$('.btn-group .btn').click(function(){
    $.post(
    'con/animalList.php',
    { selType : this.id },
    function(data)
                {
                  $('#arearesults').html(data);
                }
    );
});

I already test the bootstrap select plugin and it is also working in stand alone mode (hard coded). can you please let me know why this is happening and how I can solve this issue?

Thanks


回答1:


Multiple errors in your code.

  1. You haven't mentioned the response data-type in the $.post. Is the response data "JSON" or "html", etc?

  2. After filling the values through AJAX in the selectbox you have to refresh it. Code:

    $('#arearesults').selectpicker("refresh");
    



回答2:


this solution worked for me

  $('.selectpicker').selectpicker({});


来源:https://stackoverflow.com/questions/23399676/issue-on-loading-bootstrap-select-options-through-ajax-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!