Blog Sections Open
Using the Evolution API in a PHP AJAX Endpoint That Returns JSON
A standalone AJAX endpoint can still use Evolution snippets and context data, as long as the API is bootstrapped cleanly and the response format stays explicit.
One practical AJAX pattern in older Evolution projects is to place a lightweight PHP endpoint in the web root, bootstrap the API, and return JSON for a specific UI component. This works well when the frontend needs structured data rather than a full HTML fragment.
Typical bootstrap flow
define('MODX_API_MODE', true);
include_once dirname(__FILE__) . '/index.php';
$modx->db->connect();
if (empty($modx->config)) {
$modx->getSettings();
}
header('Content-Type: application/json');
Important detail
If the endpoint depends on the current document context, do not assume $modx->documentIdentifier will always be populated the same way it is during a normal page render. Pass the required document or gallery ID explicitly when the AJAX request is made.
That keeps the endpoint deterministic and avoids subtle bugs where a snippet works inside a page call but fails when executed from a direct AJAX script.
Getting the Number of EvoGallery Images for Each Resource in DocLister
A practical approach for showing per-resource EvoGallery image counts inside a DocLister listing.
Fixing KCFinder When Uploads and Existing Files Stop Appearing
How to debug KCFinder when it can neither upload new files nor display files that already exist on disk.