I want to display suggestions from mysql database using jQuery UI Autocomplete
I have following form
<form action="search.php" method="POST">
<input type="text" name="search" id="search-input">
<input type="submit" value="Submit" id="submit">
</form>
search.php
<?php
require_once 'db.php';
$a = array();
if (isset($_POST['search']) && !empty($_POST['search'])) {
$search_param = trim($_POST['search']);
$slct_search = $db->prepare("SELECT student_name FROM student_details WHERE student_name LIKE ?") or die($db->error);
$slct_search->bind_param('s', $search_param);
$slct_search->execute();
$res = $slct_search->get_result();
if($res->num_rows) {
while ($result = $res->fetch_object()) {
$a[] = $result->student_name;
}
echo json_encode($a);
} else {
echo 'OOPS we had a problem';
}
}
?>
The search.php working fine. it returns
["ravi","ravi"]
JS Code
$(function() {
$("#search-input").autocomplete({
source: "search.php",
minLength: 2
});
});
The Problem is when I start type in text box immediately displayed
No search results.
i also tried JQuery UI Autocomplete Search Results do not display