I have a created a PHP class that retrieves all the data from a database and gets back the results in JSON format:
public function getCategories() {
if (!$this->isConnectionAlive()) {
$this->getConnection();
}
$data = $this->dbconn->prepare("SELECT DISTINCT cat FROM regalo");
$data->execute();
$results=$data->fetchAll(PDO::FETCH_ASSOC);
$json_data = json_encode($results);
}
then an object of the class calls this method and is able to successfully do exactly that:
$dbh = new DatabaseHandler('localhost', 'fakeuser', 'fakepass', 'fakedb');
$dbh->getCategories();
How do I pass this data to my AJAX script so that it can manipulate the JSON-formatted results?
getCategoriesmethod shouldreturn $json_dataand you shouldechothe call to that method at an URL your AJAX script can access