Jquery Autocomplete UI收到了json,但仍未显示为自动填充

时间:2018-05-21 18:36:16

标签: php jquery ajax

$(document).ready(function() {
  $("#name").autocomplete({
    source: 'search.php',
    minLength: 1
  });
});
<form action='' method='get'>
  <p>
    <label>Country:</label>
    <input type='text' name='name' id="name" class='auto'>
  </p>
</form>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />

Php Code

<?php
include'../connect.php';
$term=$_GET['name'];
print_r($_GET);
$query="SELECT `studentid`,`studentname` FROM student where `studentname` like '%".$term."%' order by studentname ";
print_r($query);
$result=mysqli_query($link,$query);
$json=array();
while($student=mysqli_fetch_assoc($result)){
  print_r($student);
  $json[]=array(
    'value'=> $student['studentid'],
    'label'=>$student['studentname']." - ".$student['studentid']
  );
}
echo json_encode($json);
?>

0 个答案:

没有答案