0
index1.htmljQuery的自動完成功能(簡單的應用程序)
<html>
<head>
<link type="text/css" rel="stylesheet" media="all" href="jquery-ui-1.8.21.custom.css"/>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="presidents.js"></script>
<script type="text/javascript">
$(function() {
$("#presidentsServerInput").autocomplete({
source: 'getname1.php',
minLength: 2
})
});
</script>
</head>
<body>
<label for="presidentsServerInput">Select President (server-side): </label>
<input id="presidentsServerInput"/>
</body>
</html>
getname1.php
<?php
$searchTerm = $_GET['term'];
$results=array();
$conn = oci_connect("xxxxx", "yyyyy", "zzzzzzz");
$query = "SELECT first_name FROM employees where first_name like '" . $searchTerm . "%'";
$stid = oci_parse($conn, $query);
$r = oci_execute($stid);
echo oci_num_rows ($stid);
while ($row = oci_fetch_object($stid)) {
array_push($results,$row->FIRST_NAME);
}
echo json_encode($results);
?>
我可以在FirePHP看到它是正確打印數組,但我不在我的文本框中獲取建議。
有人能告訴我我在哪裏犯錯嗎?
是否有任何JavaScript錯誤的選擇開放和關閉方法jQuery用戶界面自動完成從例子嗎?你確定你正在訪問PHP頁面嗎? – Blazemonger
我沒有看到任何Java腳本錯誤。在fireBug上,我看到下面的「NetworkError:404 Not Found - http://localhost/app/images/ui-bg_highlight-soft_100_eeeeee_1x100.png」,我打印查詢在我的PHP - SELECT first_name FROM employees where first_name like'St%'和結果數組[「Steven」,「Steven」,「Stephen」] – Manish
不知道你是否已經看到這個,但jQuery UI有[示例](http://jqueryui.com/demos/autocomplete/#remote)與來源。 – sachleen