2012-06-07 40 views
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看到它是正确打印数组,但我不在我的文本框中获取建议。

有人能告诉我我在哪里犯错吗?

+0

是否有任何JavaScript错误的选择开放和关闭方法jQuery用户界面自动完成从例子吗?你确定你正在访问PHP页面吗? – Blazemonger

+0

我没有看到任何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

+0

不知道你是否已经看到这个,但jQuery UI有[示例](http://jqueryui.com/demos/autocomplete/#remote)与来源。 – sachleen

回答