使用Ajax在select2框中搜索内容时,出现“加载失败”错误。我的代码如下: -搜索文字 @ Html.Hidden(“ cod_indem”,将ViewBag.cod_indem作为对象)
$(function () {
$("#cod_indem").select2(
{
width: "100%",
ajax: {
type: "Get",
url: '@(Url.Action("GetAll", "Zpy_paye"))',
cache: false,
dataType: 'json',
delay: 250,
data: function (term, page) {
return {
match: term, // search term
pageIndex: page,
pageSize: 30
};
},
results: function (data, page) {
page = page || 1;
return {
results: data.items,
more: (page * 30) < data.total_count
};
}
},
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 3,
formatSelection: format,
formatResult: format
});
});
function format(data) {
return data.text;
}