I am new to javascript and ajax, I want to call php function which returns the patient age in a javascript file so I tried to explore the answers I found here concerning this question but I couldn't resolve it, here is the php file called get-patient-age.php:
function getPatientbyId($id) {
$q = DB::pdo()->prepare("SELECT p.birthday FROM patient AS p WHERE id_patient = :patient");
$q->bindValue(':patient', (int)$id , PDO::PARAM_INT);
$q->execute();
return $q->fetch(2);
}
And here is how I tried to call it using ajax:
$.ajax({
type: "GET",
url: 'get-patient-age.php',
dataType: 'json',
data: {functionname: 'getPatientbyId', arguments: 1},
success: function (obj, textstatus) {
if( !('error' in obj) ) {
;
console.log(obj.result);
} else {
console.log(obj.error);
}
}
});
I am getting 200 ok as a response but always empty, am I missing anything? Any advice could help, thanks.