2012-02-16 57 views
0

我试图通过自定义值自动完成,因此:自动完成DOS不显示结果传递自定义值

我自定义的工作价值的公司总部设在this question

使用类似的文档的默认来源:

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

萤火返回此(例如):

[... 
    { "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"}, 
    ...] 

,但问题是,当我通过定制calues ,结果的剂量出现。

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. 

不知道我错过了什么。

回答

0

一套AJAX类型= 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 
}); 
+0

AREADY尝试,同样的问题。 – 2012-02-16 12:59:07