Ajax 的 Select2 未发送请求
Select2 with Ajax is not sending request
我正在使用 Select2 版本 4.0.0 并尝试从 PHP 脚本加载远程 JSON,returns 我需要的已经格式化的数据。问题是黑暗势力在搞事情,因为我就是不能发送请求,没有错误,但是没有发送请求,就是静得像个魔鬼,我都快哭了!
我正在使用 LiveScript 和 Jade 作为 JavaScript 和 HTML 的替代品,但我会在这里翻译它们。
首先,我的标记定义了可选字段:
<select id="satan-hates-me"></select>
然后,我可以让它看起来像一个可选择的元素:
$("#satan-hates-me").select2({
placeholder: "Hail",
minimumInputLength: 1,
ajax: { // Here that bad things happen, I mean, don't happen
url: "http://localhost/os/backend/TestServiceOrder.php?req=getEquipments",
dataType: "json",
type: "GET",
quietMillis: 50,
data: function(term) { return { term: term } },
results: function(data) { return data; }
}
});
我在加载函数中执行此操作,页面加载后,它看起来是可选的,但不发送任何请求,脚本 returns 我 确实如此 要求的格式,例如:
[{id: 1, text: "Sadness"}, {id: 2, text: "Depression"}]
开始了。我可以设计编译器,但我无法让插件与 Ajax 一起工作!有人可以帮帮我吗?
问题终于解决了。
<input>
is not supported in select2 v4
。您必须使用 <select>
元素来代替
在我的例子中,这是我所有模板页脚中 .select2-Elements 的一般 select2 调用:
$('.select2').select2();
虽然我的 Ajax-Request 的 select 根本没有 class 事件(我通过 id 调用它),但我不得不将上面的内容更改为
$('select.select2').select2({theme: 'classic'});
我想 select2() 使用 class .select2 创建了几个元素,所以这可能会干扰
我正在使用 Select2 版本 4.0.0 并尝试从 PHP 脚本加载远程 JSON,returns 我需要的已经格式化的数据。问题是黑暗势力在搞事情,因为我就是不能发送请求,没有错误,但是没有发送请求,就是静得像个魔鬼,我都快哭了!
我正在使用 LiveScript 和 Jade 作为 JavaScript 和 HTML 的替代品,但我会在这里翻译它们。
首先,我的标记定义了可选字段:
<select id="satan-hates-me"></select>
然后,我可以让它看起来像一个可选择的元素:
$("#satan-hates-me").select2({
placeholder: "Hail",
minimumInputLength: 1,
ajax: { // Here that bad things happen, I mean, don't happen
url: "http://localhost/os/backend/TestServiceOrder.php?req=getEquipments",
dataType: "json",
type: "GET",
quietMillis: 50,
data: function(term) { return { term: term } },
results: function(data) { return data; }
}
});
我在加载函数中执行此操作,页面加载后,它看起来是可选的,但不发送任何请求,脚本 returns 我 确实如此 要求的格式,例如:
[{id: 1, text: "Sadness"}, {id: 2, text: "Depression"}]
开始了。我可以设计编译器,但我无法让插件与 Ajax 一起工作!有人可以帮帮我吗?
问题终于解决了。
<input>
is not supported in select2 v4
。您必须使用 <select>
元素来代替
在我的例子中,这是我所有模板页脚中 .select2-Elements 的一般 select2 调用:
$('.select2').select2();
虽然我的 Ajax-Request 的 select 根本没有 class 事件(我通过 id 调用它),但我不得不将上面的内容更改为
$('select.select2').select2({theme: 'classic'});
我想 select2() 使用 class .select2 创建了几个元素,所以这可能会干扰