【问题标题】:autocomplete dos not show result passing custom values自动完成不显示传递自定义值的结果
【发布时间】:2012-03-07 20:22:42
【问题描述】:

我正在尝试将自定义值传递给自动完成,所以:

我的自定义工作值基于this question

使用像文档这样的默认来源:

    $("#inpPesqCli").autocomplete({
        source: "ajax/search.php",
        minLength: 2,
        autoFocus: true
    });

firebug 返回此(示例):

[...
  { "id": "29083", "label": "SOME ONE 2", "value": "SOMEONE WITH LELE" },

  { "id": "19905", "label": "SOME ONE", "value": "SOMEONE WITH LALA"},
...]

工作完美,结果显现。


当我尝试设置一些自定义值时:

$("#inpPesqCli").autocomplete({
    source: function( request, response ) {
        $.ajax({
            url: "ajax/search.php",
            dataType: "jsonp",
            data: {
                featureClass: "P",
                style: "full",
                maxRows: 12,
                name_startsWith: request.term
            },
            success: function( data ) {
                response( $.map( data.geonames, function( item ) {
                    return {
                        label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                        value: item.name
                    }
                }));
            }
        });
    },
    minLength: 2,
    autoFocus: true
});

firebug 为我返回完全相同的数组结果:

  [...
  { "id": "29083", "label": "SOME ONE 2", "value": "SOMEONE WITH LELE" },

  { "id": "19905", "label": "SOME ONE", "value": "SOMEONE WITH LALA"},
  ...]

但是,问题是,当我通过自定义计算时,结果的剂量会显示出来。

php:

$type = "C";
$q = strtolower($_GET["name_startsWith"]); // this i change: custom = name_startsWith / default = term

if (!$q) return;

$res = $p->SomeClass($codemp,$q,$type);

$items = array();
while(!$res->EOF){
    $items[$res->fields["NOMCLI"]]  = $res->fields["CODCLI"];
    $res->MoveNext();
}
   // below this, i have the php autocomplete default function, if u need, ask then i post.

不知道我错过了什么。

【问题讨论】:

    标签: php jquery arrays autocomplete


    【解决方案1】:

    设置 ajax type = GET ,可能有效,默认数据发送类型为 POST

        $("#inpPesqCli").autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "ajax/search.php",
                dataType: "jsonp",
                type : "GET",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    name_startsWith: request.term
                },
                success: function( data ) {
                    response( $.map( data.geonames, function( item ) {
                        return {
                            label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                            value: item.name
                        }
                    }));
                }
            });
        },
        minLength: 2,
        autoFocus: true
    });
    

    【讨论】:

      猜你喜欢
      • 2013-07-10
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      相关资源
      最近更新 更多