通过Ajax发布加载Bootstrap选择选项 [英] Loading Bootstrap select options through Ajax post

查看:311
本文介绍了通过Ajax发布加载Bootstrap选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Bootstrap 3和Bootstrap-Select插件,我试图从数据库中加载ajax的select下拉选项.

Using Bootstrap 3 and Bootstrap-Select plugin, I am trying to load the options of the select drop down by ajax from database.

当我从select元素中删除select picker类但该类(使用Bootstrap select必需)时,该代码可以正常工作,而不会加载任何选项.

The code works perfectly when I remove the select picker class from the select element but with that class (which is required to use Bootstrap select) it is not loading any of the 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);
                }
    );
});

我已经测试了Bootstrap select插件,它也可以在独立模式下工作(硬编码).我该如何解决这个问题?

I already test the Bootstrap select plugin and it is also working in stand alone mode (hard coded). How can I solve this issue?

推荐答案

您的代码中存在多个错误.

Multiple errors in your code.

  1. 您没有在$.post中提到响应data-type.响应数据是"JSON"还是"html"等?

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

通过AJAX在选择框中填充值之后,您必须刷新它. 代码:

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

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

这篇关于通过Ajax发布加载Bootstrap选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆