Select2 不发送远程参数

Select2 is not sending remote parameters

我正在尝试将参数发送到一个 servlet,但我做不到,这是可行的, 我总是收到 "null"。 我在网上找到了一些示例,但 none 对我有用。 有人可以告诉我为什么不起作用吗? 这是我的代码:

        $('#cboCli').empty();
        $('#cboCli').select2({
            theme: "bootstrap",
            width: "100%"
        });
        $('#cboCli').append("<option>Cargando ...</option>");
        $.ajax({
            type: "POST",
            url: "Cuenta",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: function (term, action,tipocuen) {
                return {
                    action: 'BUSCACONSULTA',
                    tipocuen: $("#cboTipoCue").val(),
                    term: term
                };
            },                
            success: function (data) {
                $('#cboCli').empty();
                $.each(data.aaData, function (i, data) {
                    $('#cboCli').append('<option value="' + data.id + '">' + data.nombre + '</option>');
                });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("Ocurrio un Error: " + XMLHttpRequest.responseText);
            }
        });

参数"action"和"tipocuen",永远不会到达我的servlet! 提前致谢!

data $.ajax 的参数错误。如jQuery api document所述,数据必须是PlainObjectStringArray

更改如下:

data: {
     action: 'BUSCACONSULTA',
     tipocuen: $("#cboTipoCue").val(),
     term: term
},

而且我认为这与jquery-select2无关。

如果您想正确发送参数,我认为您应该将 $.ajax 绑定到某个事件。