我正在尝试通过ajax使chosen select
的搜索框工作,并使用其结果填充下拉列表。
$("#ContentPlaceHolder1_ES1_ddlInstructor1_chosen input").change(function () {
console.log($(this).val());
FillList($(this).val(), "<%=Request.Url.AbsolutePath%>/FillList", "#<%=ddlInstructor1.ClientID%>");
});
function FillList(Search, url, Sub) {
$.ajax({
type: "POST",
url: url,
data: "{ 'Search': '" + Search + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$(Sub).empty();
if (data.d.length > 1)
$(Sub).html($('<option></option>').val("").html("Seçiniz.."))
for (var i = 0; i < data.d.length; i++) {
$(Sub).append($('<option></option>').val(data.d[i].UId).html(data.d[i].Text));
}
if (data.d.length == 1)
$(Sub).change();
$(Sub).trigger("chosen:updated");
}
});
}