I am making an AJAX call to my PHP script, via $.getJSON. The problem is, PHP is returning json-encoded data, but my script is not console.logging anything at all.
function Club(){
this.URL = "http://localhost/imp03/includes/ajaxCall.php";
}
Club.prototype.loadData = function(){
$.getJSON(Club.URL, function(data){
console.log(data);
});
}
There are no errors in the console, and this is my PHP script.
$db = new Database(HOST, USER, PASS, DB);
$array = $db->getData();
header('Content-Type: application/json');
echo json_encode($array);
exit;
This is the method in my Database class, responsible for getting data
public function getData(){
try{
$sql = $this->db->prepare("SELECT * FROM inlever3");
$sql->execute();
$result = $sql->fetchAll();
return $result;
} catch(PDOException $e){
echo $e;
return false;
}
}
http://localhost/imp03/includes/ajaxCall.phpin your browser ?