I have to do an auto complete text box in my app using jquery-ui. I have this Ajax script to get data from database:
<script>
$( function() {
$("#searchTxt").on('keyup', function(){
searchTxt = $("#searchTxt").val();
$.ajax({
url: '../php/autoComplete.php',
data: {searchTxt: searchTxt},
type: 'GET',
dataType: 'JSON',
success:function(resp)
{
$.each( resp, function(key, result)
{
var availableTags = result['patient_name_en'];
$( "#searchTxt" ).autocomplete({
source: availableTags
});
});
},
error:function(resp)
{
console.log(resp)
}
})
} );
});
</script>
And here is the autoComplete.php script:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once('connection.php');
$cid = $_SESSION['clinic_id'];
$searchTxt = '%'.$_GET['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);
?>
The problem is that I can see the data returned at the network tab of the developer tool but with another file returned with an error of The requested URL /ncd/... was not found on this server.
Here is an image of the situation where I can see an array returned with no errors:
And here is the other red file:
At the console:
I tried to change the type from get
to post
but still the same problem.