I am adding an autocomplete library into my project using the jquery-ui library.
I created the PHP script from which I need to get the data:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once('connection.php');
$cid = $_SESSION['clinic_id'];
$searchTxt = '%'.$_POST['searchTxt'].'%';
$res = array();
$getPatients = "SELECT * FROM patient WHERE clinic_id = :cid and patient_name_en LIKE :searchTxt ORDER BY patient_id DESC";
$execGetPatients = $conn->prepare($getPatients);
$execGetPatients->bindValue(':cid', $cid);
$execGetPatients->bindValue(':searchTxt', $searchTxt);
$execGetPatients->execute();
$getPatientsResult = $execGetPatients->fetchAll();
$i = 0;
foreach($getPatientsResult as $result)
{
$res[$i] = $result;
$i++;
}
echo json_encode($res);
?>
And the JavaScript part is here:
<script>
$( function() {
$("#searchTxt").on('keyup', function(){
searchTxt = $("#searchTxt").val();
$.ajax({
url: '../php/autoComplete.php',
data: {searchTxt: searchTxt},
type: 'POST',
dataType: 'JSON',
success:function(resp)
{
$.each( resp, function(key, result)
{
var availableTags = result['patient_name_en'];
});
},
error:function(resp)
{
console.log(resp)
}
})
} );
$( "#searchTxt" ).autocomplete({
source: availableTags
});
});
</script>
I had the following error in the console about jQuery:
Maximum call stack size exceeded.
But now it gone somehow, and I don't know why.
Now after typing in the search text box, I am getting an empty array at the network tab of the developer tool or an array but with no properties and nothing is show as autocomplete near the text box:
EDIT
I changed a line in PHP into:
$searchTxt = '%'.$_POST['searchTxt'].'%';
And now no php errors, but a JavaScript error:
Uncaught ReferenceError: availableTags is not defined


