Jquery自动完成不是自动完成的

时间:2014-05-20 19:25:41

标签: php jquery ajax

我已经使用php文件设置了jquery自动完成功能,以便从数据库中获取数据并将其解析为json。问题是当我开始输入员工的名字时,我得到的不仅仅是员工的名单。以下是我的代码。

 <script type="text/javascript">
  $(function(){
    $("#employee").autocomplete({
        source:"allemployeesjson.php",
        minLength:1
    });
   });
 </script>
</head>
<body>
  <div>
    <label for="employee">Employee:</label>
    <input id="employee" />
</div>
</body>

1 个答案:

答案 0 :(得分:0)

我已经弄清楚问题是什么。原始的php文件是下面的文件。 我没有为了更新数据而加入它。

<?php
session_save_path("../itshear");
session_start();
include('../common.php');
$appquery = "select SSN,cast(rtrim(Lastn)+', '+rtrim(Firstn) as varchar(60))  employee from datatable where mchEmploy = '1' and Persontypeid = '2' order by employee";
$emplist=sqlsrv_query($link,$appquery,array(),array( "Scrollable" => 'static' )) or die('Cannot get employee list');
unset($_SESSION['employees']); 
while ($row = sqlsrv_fetch_array($emplist,SQLSRV_FETCH_ASSOC)) {
    $_SESSION['employees'][]=array('value'=>$row['employee'],'ssn'=>$row['SSN']);
    }
 $_SESSION['json']['employees']= json_encode($_SESSION['employees']);
 echo $_SESSION['json']['employees'];
?>

这是已更改的文件,它运行正常。

<?php
session_save_path("../itshear");
session_start();
include('../common.php');
$q = $_GET['term'];
if(!$q){return;}
$appquery = "select Mchnum,SSN,cast(rtrim(Lastn)+', '+rtrim(Firstn) as varchar(60))  employee from datatable where mchEmploy = '1' and Persontypeid = '2' and Lastn like '".$q."%' order by employee";
$emplist=sqlsrv_query($link,$appquery,array(),array( "Scrollable" => 'static' )) or die('Cannot get employee list');
unset($_SESSION['employees']); 
while ($row = sqlsrv_fetch_array($emplist,SQLSRV_FETCH_ASSOC)) {
    $_SESSION['employees'][]=array('value'=>$row['employee'],'ssn'=>$row['SSN']);
    }
 $_SESSION['json']['employees']= json_encode($_SESSION['employees']);
 echo $_SESSION['json']['employees'];
?>