http://www.devbridge.com/projects/autocomplete/jquery/からこの自動提案を実装しようとしています
私の PHP コードは機能していませんが、ルックアップ関数は結果のみを表示しています。このことについて私を導いてください。
ここに私のコードがあります:
$(document).ready(function()
{
$('#searchresult').autocomplete(
{
serviceUrl: 'source.php',
minChars: 1,
delimiter: /(,|;)\s*/, // regex or character
maxHeight: 400,
zIndex: 9999,
deferRequestBy: 0, //miliseconds
noCache: false, //default is false, set to true to disable caching
// callback function:
onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },
// local autosugest options:
lookup: ['January', 'February', 'March', 'April', 'May'] //local lookup values
});
});
PHP コード: source.php
<?php
include "config/config.php";
require "jsonwrapper/jsonwrapper.php";
//$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends
//$qstring = "SELECT description as value,id FROM tblcompanies WHERE description LIKE '%".$term."%'";
$result = mysql_query("SELECT fieldDesc AS value, fieldID AS id FROM table");
$data = array();
while ($row = mysql_fetch_array($result))//loop through the retrieved values
{
$row['value'] = htmlentities(stripslashes($row['value']));
$row['id'] = (int)$row['id'];
$data[] = $row;//build an array
}
echo json_encode($data);//format the array into json data
?>
このタイプの jquery autosuggest を実装する場合は共有してください。どんな提案でもうれしいです。