데이터베이스의 레코드를 검색 할 수있는 검색 창을 만들고 싶습니다.항목에 대한 Jquery UI 자동 완성 링크
search.php은 다음과 같습니다
ReferenceError: item is not defined
나는 일이 원하는 것은 그러나
$("#tags").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
window.location = ("customers.php?action=view&cid=" + item.id)
//$('#tags').val(ui.item.id);
//return false;
}
})
.data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a href='customers.php?action=view&cid="+ item.id + "'>"+ item.label + "</a>")
.appendTo(ul);
};
가이 오류를 제공합니다
<?php
// connect to mysql
require_once('includes/connect.php');
// include config
include('includes/config.php');
$nameser = $_GET['term'];
$names = array();
$result = mysql_query("SELECT name,customerid FROM customers WHERE name LIKE '%".$nameser."%' ORDER BY name ASC");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$row_array['id'] = $row['customerid'];
$row_array['value'] = htmlentities($row['name']);
array_push($names,$row_array);
}
echo json_encode($names);
?>
자바 스크립트 부분은 다음과 같습니다 결과 목록에서 뭔가를 클릭하면 URL로 리디렉션됩니다.
customers.php?action=view&cid={CustomerID}
누구나 아이디어가 있습니까?
편집 :
올바른 자바 스크립트 코드 작동 :
$("#tags").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
window.location = ("customers.php?action=view&cid=" + ui.item.id)
//$('#tags').val(ui.item.id);
//return false;
}
})
.data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a href='customers.php?action=view&cid="+ item.id + "'>"+ item.label + "</a>")
.appendTo(ul);
};
라인 5, js : 항목이 무엇입니까? 전역 변수? – madfriend
@Alex : 실제로 모르겠지만 - 13 행에서 작동합니다. 스크립트는 다른 게시물의 일부 복사/붙여 넣기입니다. –
라인 13'item'은 _renderItem 함수에 전달 된 인자이므로 괜찮습니다. 'select' 이벤트 전에 어떻게 링크가 보이는지 게시하십시오. – madfriend