【发布时间】:2015-06-03 20:45:27
【问题描述】:
我尝试使用“devbridge autocomplete”中的插件:https://www.devbridge.com/sourcery/components/jquery-autocomplete/ 我想从我的 search.php 页面中获取 3 个值(而不仅仅是 1 个)。 它适用于“value”,但不适用于“data1”和“data2”(每个 = null 的结果)
我的 jQuery 代码:
$('#search-adress').autocomplete({
serviceUrl: 'search.php',
dataType: 'json',
onSelect: function (value,data1,data2) {
alert('You selected: ' + value + ', ' + data1 + ', ' + data2);
}
});
我的搜索页面:
$term=$_GET['query'];
$query = mysql_query("select distinct adress,id,city from myadresstable where (adress like '%{$term}%') order by adress limit 10 ");
if (mysql_num_rows($query))
{
while($row = mysql_fetch_assoc($query))
{
$reply['suggestions'][] = ''.utf8_encode($row['nom_voie']).'';
$reply['data1'][] = ''.utf8_encode($row['id']).'';
$reply['data2'][] = ''.utf8_encode($row['city']).'';
}
echo json_encode($reply);
}
谢谢你帮助我:)
【问题讨论】:
-
我的问题在于 devbridge 的脚本而不是 jquery-ui
-
你应该在你的 php 代码中使用
json_encode:json_encode($reply); -
对不起,我忘了写在这里,但我的源代码中有 json_encode。
标签: php jquery mysql ajax autocomplete