【问题标题】:How to bind data from ajax to chosen jquery?如何将数据从 ajax 绑定到选定的 jquery?
【发布时间】:2015-12-14 02:57:02
【问题描述】:

我使用了从

中选择的 jquery
https://github.com/harvesthq/chosen/releases

我从 ajax webservices 绑定数据,似乎它不起作用。数据未在选择中加载。

  $(".cb_bu_info").chosen({
                no_results_text: "Oops, nothing found!",
                width: "50%",
                source: function () {
                    $.ajax({
                        type: "POST",
                        url: "../BUS/WebService.asmx/LIST_BU",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        //beforeSend: function () { $('ul.cb_bu_info').empty(); },
                        success: function (data) {
                            $("#cb_bu_info").html('');
                            $.each($.parseJSON(data.d), function (idx, obj) {
                                $("#cb_bu_info").append('<option value="' + obj.BU_ID + '">' + obj.BU_NAME + '</option>');
                            });
                        },
                        error: function (data) {
                            console.log(data.d);
                            alert("An error occurred !");
                        }
                    });
                }
            });
&lt;select class="cb_bu_info"&gt;&lt;/select&gt;

谢谢大家。

【问题讨论】:

标签: jquery ajax html select jquery-chosen


【解决方案1】:

您可以在页面加载后使用此示例,然后在选择列表中加载国家/地区。

确保您已添加参考资料。

<select id='CountryName'>
<option> </option>
</select>
$(document).ready(function () {
    var frontDropdown = "";
    $.ajax({
        url: baseUrl + "GetBPCountriesCombo",
        type: "GET",
        async: true,
        success: function (result) {
            frontDropdown += "<option value='null'> Select Country </option>";
            $.each(result, function (i, data) {
                frontDropdown += "<option " + " value=" + data.CountryId + ">" + data.CountryName + "</option>";
            })
            $('#CountryName').append(frontDropdown).trigger('chosen:updated').css("width", "auto");;
        },
        error: function () {
            alert("An error occurred !");
        }
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 2016-11-19
    • 2012-05-29
    • 1970-01-01
    相关资源
    最近更新 更多