Select2与Ajax没有发送请求 [英] Select2 with Ajax is not sending request
问题描述
我正在使用Select2版本4.0.0,并尝试从PHP脚本加载远程JSON,该脚本返回我需要的已格式化数据.问题在于,黑暗的力量正在制造某种东西,因为我只是无法发送请求,没有错误,但是没有发送请求,它像魔鬼一样安静得让我几乎哭泣!
I'm using Select2 version 4.0.0 and trying to load a remote JSON from a PHP script that returns the already formated data that I need. The problem is that the forces of the darkness are making something, because I just can't send the request, there is no error, but there is no request sent, it just stays so quiet as a devil that I'm almost crying!
我正在使用LiveScript和Jade替代JavaScript和HTML,但我将在此处进行翻译.
I'm using LiveScript and Jade as alternatives to JavaScript and HTML, but I'll translate'em here.
首先,我的标记定义了可选字段:
First, my markup defines the selectable field:
<select id="satan-hates-me"></select>
然后,我可以使其看起来像一个可选元素:
Then, I'm able to make it look like a selectable element:
$("#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; }
}
});
我正在执行此操作,将其包装在加载函数中,在页面加载后,它看起来像是可选的,但是没有发送请求,并且脚本完全返回了我所需的格式,例如:
I'm performing this wrapped in a load function, after page loading, it looks like a selectable, but sends no requests, and the script returns me exactly the required format, as example:
[{id: 1, text: "Sadness"}, {id: 2, text: "Depression"}]
然后去.我可以设计编译器,但实际上我无法使插件与Ajax一起使用!有人可以帮我吗?
And here goes. I can design compilers but I can't in the world make a plugin work with Ajax! Can somebody help me, please?
推荐答案
最终解决了该问题.
select2 v4不支持
<input>
<input>
is not supported in select2 v4
.您必须改为使用<select>
元素
这篇关于Select2与Ajax没有发送请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!