jQuery自动完成(简单应用程序)

时间:2012-06-07 16:41:27

标签: php jquery oci

index1.html

<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中看到它正确打印数组,但我没有在我的文本框中得到建议。

有人可以告诉我我在哪里弄错了吗?

1 个答案:

答案 0 :(得分:0)

从jQuery http://jqueryui.com/demos/autocomplete/#remote-jsonp上的示例中查看jQuery UI自动完成的open select和close方法