0

ID aktForm_tiekejas の入力があり、jquery オートコンプリート コードです。

$('#aktForm_tiekejas').autocomplete({
serviceUrl: '_tiekejas.php',
width: 185,
deferRequestBy: 0,
noCache: true,
onSelect: function(suggestion) {alert('You selected:'+suggestion.value+','+suggestion.data);}
});

_tiekejas.php:

<?php
include("../Setup.php");
$query = ($_GET['query']);
$reply = array();
$reply['query'] = $query;
$reply['suggestions'] = array();
$reply['data'] = array();
$res = mysql_query("SELECT id,pavadinimas FROM sarasas_tiekejas WHERE pavadinimas LIKE '%$query%' ORDER BY pavadinimas ASC");
while ($row = mysql_fetch_array($res)) {
 $reply['suggestions'][] = $row['pavadinimas'];
 $reply['data'][] = $row['id'];
}
mysql_close();
echo json_encode($reply);
?>

クエリが 'vac' の場合、php はサーバーから次のように返します。

{"query":"vac","suggestions":["UAB Vivacitas"],"data":["866"]}

しかし

alert('You selected:'+suggestion.value+','+suggestion.data); 

データを警告しません (866)

どうして?...

4

1 に答える 1