这是我的代码
$("input#shopName").autocomplete({ source: "getShop.PHP",minLength: 2 });
从PHP返回的JSON值如下所示
if(isset($_GET["term"])){ $query=$_GET["term"]; $result = $dataset->get_custom_record("SELECT * FROM mc_shop WHERE shop_title like '%" . $query . "%' ORDER BY id"); } while ($row = MysqL_fetch_array($result,MysqL_ASSOC)) { $row_array['id'] = $row['id']; $row_array['value'] =$row['shop_title']; array_push($return_arr,$row_array); } echo json_encode($return_arr);
解决方法
$("input#shopName").autocomplete({ source: "getShop.PHP",minLength: 2,select: function(event,ui) { $("#theHidden").val(ui.item.id) } });