Php 不显示JQuery UI自动完成搜索结果

Php 不显示JQuery UI自动完成搜索结果,php,jquery,mysql,json,jquery-ui-autocomplete,Php,Jquery,Mysql,Json,Jquery Ui Autocomplete,我使用php从mysql数据库中没有得到任何搜索结果 PHP代码: JQuery代码: 试试这个: $("#search").autocomplete({ source: "../searchclient.php", minLength: 1, }).data("autocomplete")._renderItem = function(ul, item) { return $("<li>").data("item.autocomplete", item).a

我使用php从mysql数据库中没有得到任何搜索结果

PHP代码:

JQuery代码:

试试这个:

$("#search").autocomplete({
    source: "../searchclient.php",
    minLength: 1,
}).data("autocomplete")._renderItem = function(ul, item) {
    return $("<li>").data("item.autocomplete", item).append("<a>" + item.value + "</a>").appendTo(ul);
}; 

我沿着AJAX路线走,这似乎奏效了:

HTML

SEARCHCLIENT.PHP


我刚试过这个,不,它不起作用。这就好像数据没有从php返回到jquery中一样。是的,正如我提到的,当源代码硬编码到jquery中时,它会工作。但是,如果我想使用php查询数据库,例如source:/searchclient.php,即使php文件的输出是[{value:Hello World},{value:East Meets West JV}],它也不起作用。因此,我知道searchclient.php正在输出正确的数据,但它没有将其返回到jquery中。如果我直接转到localhost:9080/searchclient.php/?term=e,那么数据输出[{value:Hello World,id:1,label:Hello World},{value:East Meets West JV,id:2,label:East Meets West JV}]。请参阅更新的PHP代码,我添加了ID和标签。您可以将代码放在任何服务器上吗。从那里我可以检查它。我的debug.log是说PHP注意:未定义的索引:C:\path中的term。因此,$q=$\u GET[term]这一行肯定有问题;你知道为什么会这样吗?
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>

<script type="text/javascript">
$(function() {

    //autocomplete
    $("#search").autocomplete({
        source: "../searchclient.php",
        minLength: 1,
    });             

});
</script>
<input type="text" name="search" id="search" placeholder="Search for Business Name" />
require_once "connectmysql.php";
$belongsto=$current_user->businessname;
$q = $_GET["term"];
if (!$q) return;
$sql = "select clientname as value, idzb_clients as id from zb_clients where clientname LIKE '%".$q."%' AND belongsto='".$belongsto."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $row['id']=htmlentities(stripslashes($row['id']));
    $row['value']=htmlentities(stripslashes($row['value']));
    $row['label']=htmlentities(stripslashes($row['value']));
    $row_set[] = $row;
}
echo json_encode($row_set);
$("#search").autocomplete({
    source: "../searchclient.php",
    minLength: 1,
}).data("autocomplete")._renderItem = function(ul, item) {
    return $("<li>").data("item.autocomplete", item).append("<a>" + item.value + "</a>").appendTo(ul);
}; 
$( "#search" ).autocomplete({
  source: function( request, response ) {
    $.ajax({
      url: "../searchclient.php",
      dataType: "json",
      data: {
        q: request.term
      },
      success: function( data ) {
        response( data );
      }
    });
  },
  minLength: 1
});
<?php

require_once "connectmysql.php";
$belongsto = $current_user->businessname;
$q = $_GET['q'];
$sql = "select clientname as value, idzb_clients as id, has_ledger_setup from zb_clients where clientname LIKE '%".$q."%' AND belongsto='".$belongsto."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $row['id'] = htmlentities(stripslashes($row['id']));
    $row['value'] = htmlentities(stripslashes($row['value']));
    $row['label'] = htmlentities(stripslashes($row['value']));
    $row_set[] = $row;
}
header('Content-Type: application/json');
echo json_encode($row_set);

?>