Jquery UI自动完成ajax不会填充下拉框

我需要帮助,我看不出问题出在哪里。

当我在html文件中设置自动完成源时,它工作正常,当我在ajax.php中打印出相同的源或数据库值并通过ajax返回它时它不起作用。 可能是什么问题呢? 请帮忙。

Html:

    Auto complete     .ui-autocomplete-loading { background: url("images/loader.gif") no-repeat scroll right center white; }   jQuery(document).ready(function($){ $("#ac").autocomplete({ minLength: 2, //source: [{"value":"Some Name","id":1},{"value":"Some Othername","id":2}] source: function( request, response){ $.ajax({ type: 'GET', url: 'ajax.php', data: { 'term':request.term }, contentType: "application/json; charset=utf-8", dataType: "json", success: function(data){ console.log('Success : ' + data); }, error: function(message){ alert(message); } }); }, select: function( event, ui ) { } }); });       

和我的ajax.php文件:

 $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'test_db'; $server = mysql_connect($dbhost, $dbuser, $dbpass); $connection = mysql_select_db($dbname, $server); $term = $_GET['term']; $qstring = "SELECT user_id,tName FROM `csv_data` WHERE tName LIKE '%" . $term . "%'"; $result = mysql_query($qstring); $return_arr = array(); $i = 0; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {//loop through the retrieved values $row_a = array(); if ($row['tName'] != null) { $i++; $row_a['value'] = ($row['tName']); $row_a['id'] = (int) $i; array_push($return_arr, $row_a); } } mysql_close($server); header("Content-type: text/x-json"); /*$my_arr = array( array("value" => "Some Name", "id" => 1), array("value" => "Some Othername", "id" => 2) );*/ //echo json_encode($return_arr); print json_encode($return_arr); //print json_encode($my_arr); 

这是来自firebug的响应(从数据库生成)。

 [{"value":"4 erste Spiele","id":1},{"value":"Meine ersten Spiele \"Blinde Kuh\"","id":2},{"value":"4 erste Spiele","id":3},{"value":"Meine ersten Spiele \"Blinde Kuh\"","id":4},{"value":"4 erste Spiele","id":5},{"value":"Meine ersten Spiele \"Blinde Kuh\"","id":6},{"value":"Maxi Kleine Spielewelt","id":7}] 

参数response实际上是一个必须调用的回调 – 将数据传递给它 – 以显示结果弹出菜单。 只需在“成功”回调中调用它:

 source: function(request, response) { $.ajax({ ... success: function(data) { // pass your data to the response callback response(data); }, error: function(message) { // pass an empty array to close the menu if it was initially opened response([]); } }); },