我正在尝试将自定义值传递给自动填充,因此:
我的自定义工作值基于this question
使用默认来源,例如doc's:
$("#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.
不知道我错过了什么。
答案 0 :(得分:0)
设置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
});