好吧,我在使用JQuery自動完成時遇到問題。JQuery UI自動完成JSON php輸出格式
在搜索欄中,當我開始輸入時,它只顯示searchfrnds.php的firstname。我想要的是,它應該以某種方式連接searchfrnds.php的結果,以便在顯示的搜索結果下拉列表中顯示名字以及姓氏。
代碼searchfrnds.php:
<?php
$term = trim(strip_tags($_GET['term']));
$query = "SELECT aid,firstname, lastname, profpic,email,abtyou
FROM artist92 WHERE firstname LIKE '%".$term."%' OR lastname LIKE '%".$term."%'";
$result = mysqli_query ($link, $query);
$array = array();
while($obj = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$array['value'] = $obj['firstname'];
$array['lvalue'] = $obj['lastname'];
$array['icon'] = $obj['profpic'];
$array['aid']=$obj['aid'];
$array['abt']=$obj['abtyou'];
$array['email']=$obj['email'];
$row_set[]=$array;
}
echo json_encode($row_set);
?>
JQuery的代碼:
<script>
$(function() {
function log(message) {
$("<div>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#frndsrch").autocomplete({
source: "searchfrnds.php",
minLength: 2,
select: function(event, ui) {
$("#project-icon").attr("src", "" + ui.item.icon);
$('a').attr('href',"viewartprofile.php?aid=" + ui.item.aid);
}
});
});
</script>
寫你jQuery代碼不僅PHP .. – Svetoslav