Blog Sections Open
A Safer AJAX Routing Pattern for Evolution CMS with OnPageNotFound
A better AJAX pattern keeps routing explicit, avoids unsafe open snippet execution, and still fits naturally into Evolution CMS.
Older Evolution projects often relied on improvised AJAX entry points such as generic index-ajax.php handlers or loading entire pages and scraping out a single block. Both approaches work, but neither ages well.
Why the old patterns are fragile
- open snippet execution can become a security problem
- full-page loading is wasteful and awkward for structured responses
- logic becomes scattered between pages, snippets, and front-end hacks
A better pattern
Route explicit AJAX endpoints through a plugin listening on OnPageNotFound, then branch only for a controlled whitelist of request aliases.
switch ($_GET['q'] ?? '') {
case 'liked':
echo $_POST['value'] . '-OK';
break;
}
exit;
The important part is not the tiny example itself. The important part is the discipline: define only the endpoints you intend to expose, keep the handler logic explicit, and return lean payloads instead of entire page renders.
For modern projects, the same idea still applies even if the implementation later moves into a more formal controller layer.
Keeping eForm AJAX Results Inside a Modal Window
How to submit an eForm form from a modal and render the validation or thank-you response back into that same modal.
Routing Different WebLoginPE Users to Different Account Dashboards
How to send different user types to separate personal account pages after authentication with WebLoginPE.