jQuery select2 AJAX不起作用 [英] jQuery select2 AJAX not working

查看:530
本文介绍了jQuery select2 AJAX不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery select2插件并试图使AJAX与我的ext数据一起使用,这显然无法正常工作,我只是想知道是否有人可以指出我做错了什么或缺少什么?/p>

注意这仅适用于部分v3.5.2

我的js:

$('#cliselect').select2({
    ajax: {
        dataType: "json",
        url: "clientprojectpopulate.php",
        results: function (data) {
            return {results: data};
        }
    }
});

html:

<select id="cliselect" name="cliselect" style="width: 100%;" /></select>

我的JSON返回(我认为这是有效的):

[{"id":"62","text":"Alberta Innovates Health Solutions"},{"id":"4","text":"Alterna Savins & Credit Union"},{"id":"63","text":"BC Patient Safety & Quality Council"}]

解决方案

找出原因,因为我使用的是<select>

加载ajax数据必须为<input> ...

<input type="hidden" id="cliselect" name="cliselect" style="width: 100%;" />

I'm using the jQuery select2 plugin and trying to get the AJAX to work with my ext data which is obviously not working and I'm just wondering if someone can point out what I'm doing wrong or missing something?

NOTE This is only for select v3.5.2

my js:

$('#cliselect').select2({
    ajax: {
        dataType: "json",
        url: "clientprojectpopulate.php",
        results: function (data) {
            return {results: data};
        }
    }
});

html:

<select id="cliselect" name="cliselect" style="width: 100%;" /></select>

my JSON returns (which I believe is valid):

[{"id":"62","text":"Alberta Innovates Health Solutions"},{"id":"4","text":"Alterna Savins & Credit Union"},{"id":"63","text":"BC Patient Safety & Quality Council"}]

解决方案

Figured out its because i was using <select>

It has to be an <input> for the ajax data to load...

<input type="hidden" id="cliselect" name="cliselect" style="width: 100%;" />

这篇关于jQuery select2 AJAX不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆