I am trying to use JQuery autocomplete feature using separate php script as source. When I use static table directly in JQuery as source, it works flawlessly:
$(function() {
$( ".auto" ).autocomplete({
source: ["Choice1", "Choice2"],
minLength: 1
});
});
But when I change the source to the php file (which is located in the same folder), the autocomplete feature doesn't seem to work.
$(function() {
$( ".auto" ).autocomplete({
source: 'search.php',
minLength: 1
});
});
Here is rest of my code related to autocomplete
Input field:
<tr>
<div class="ui-widget">
<td class="tg-031e"><form action="" method="post"><input type="text" class="txtbox auto ui-autocomplete-input" value=""/></form></td>
</div>
</tr>
Php script:
<?php
include_once 'php/database_connect.php';
$searchTerm = $_GET['term'];
$query = $conn->query("SELECT type FROM material");
while ($row = $query->fetch_assoc()) {
$data[] = $row['type'];
}
echo json_encode($data);
?>
P.S. Its not up to database connection ($conn), because I use it in other scripts without any problem.