PHPackages                             richardhj/contao-simple-ajax - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. richardhj/contao-simple-ajax

Abandoned → [symfony/routing](/?search=symfony%2Frouting)Contao-bundle[HTTP &amp; Networking](/categories/http)

richardhj/contao-simple-ajax
============================

More control over your AJAX requests.

v1.3.2(7y ago)63.4k3LGPL-3.0+PHPPHP ^5.6 || ^7.0

Since Oct 7Pushed 4y ago4 watchersCompare

[ Source](https://github.com/richardhj/contao-simple-ajax)[ Packagist](https://packagist.org/packages/richardhj/contao-simple-ajax)[ RSS](/packages/richardhj-contao-simple-ajax/feed)WikiDiscussions v1.3 Synced 4d ago

READMEChangelog (7)Dependencies (3)Versions (9)Used By (0)

SimpleAjax for Contao Open Source CMS
=====================================

[](#simpleajax-for-contao-open-source-cms)

SimpleAjax provides an endpoint for Ajax endpoints.

While it has been very convenient for Contao 3, this extension is not required for Contao 4 anymore. You should only use this extension in case your extension needs to be compatible with Contao 3 and Contao 4. Find the upgrade instructions below.

Changelog
---------

[](#changelog)

v1.1.0 introduces the `SimpleAjax\Event\SimpleAjax`. You are able to register an event listener. If you're not using composer, you might want to use v1.0 instead and use the legacy hooks.

v1.2.0 lets you set an `Response` instance (from the symfony/http package). This was introduced to prepare a smooth upgrade process to Contao 4.

v1.3.0 is the Contao 4 release with equal features. The extension will not include any features as Contao 3 is approaching EOL.

Usage
-----

[](#usage)

### Per Event

[](#per-event)

At first: Listen on the event `SimpleAjax\Event\SimpleAjax` using one [method described here](https://github.com/contao-community-alliance/event-dispatcher#event-listener-per-configuration).

#### Either: Set a `Response` (recommended)

[](#either-set-a-response-recommended)

```
class MyAjaxListener
{
   public function myMethod(\SimpleAjax\Event\SimpleAjax $event)
   {
       if ('myrequest' !== \Input::get('acid'))
       {
           return;
       }

       $return = ['foo', 'bar', 'foobar'];
       $response = new \Symfony\Component\HttpFoundation\JsonResponse($return);
       $event->setResponse($response);
   }
}
```

#### Or: Handwritten response with termination (legacy)

[](#or-handwritten-response-with-termination-legacy)

```
class MyAjaxListener
{
   public function myMethod(\SimpleAjax\Event\SimpleAjax $event)
   {
       if ('myrequest' !== \Input::get('acid'))
       {
           return;
       }

       // Check whether the SimpleAjaxFrontend.php was requested
       if (false === $event->isIncludeFrontendExclusive())
       {
           return;
       }

       $return = ['foo', 'bar', 'foobar'];

       header('Content-Type: application/json');
       echo json_encode($return);
       exit;
   }
}
```

### Per Hook (legacy)

[](#per-hook-legacy)

```
// config.php
$GLOBALS['TL_HOOKS']['simpleAjax'][] = array('MyClass', 'myMethod');
$GLOBALS['TL_HOOKS']['simpleAjaxFrontend'][] = array('MyClass', 'myMethod'); // Use this hook for front end exclusive hooks

// MyClass.php
class MyClass
{
   public function myMethod()
   {
       if ('myrequest' === \Input::get('acid'))
       {
           $return = ['foo', 'bar', 'foobar'];

           header('Content-Type: application/json');
           echo json_encode($return);
           exit;
       }
   }
}
```

Upgrade to Contao 4
-------------------

[](#upgrade-to-contao-4)

This extension has been very convenient for Contao 3. While upgrading to Contao 4, you are advised to use the routing features coming with Contao 4.

In case you want to build an AppBundle (that's most probably true if you are no extension developer): [Create an AppBundle](https://community.contao.org/de/showthread.php?69448-GEL%C3%96ST-AppBundle-lokale-Extension-Managed-Edition&p=462159&viewfull=1#post462159)

Implement the `RoutingPluginInterface` in your Contao Manager Plugin and load the routing.yml with the `getRouteCollection()`.

```
-class Plugin implements BundlePluginInterface
+class Plugin implements BundlePluginInterface, RoutingPluginInterface
{
    public function getBundles(ParserInterface $parser): array
    {
        // …
    }
+
+    /**
+     * Returns a collection of routes for this bundle.
+     *
+     * @param LoaderResolverInterface $resolver
+     * @param KernelInterface         $kernel
+     *
+     * @return RouteCollection|null
+     *
+     * @throws \Exception
+     */
+    public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
+    {
+        return $resolver
+            ->resolve(__DIR__.'/../Resources/config/routing.yml')
+            ->load(__DIR__.'/../Resources/config/routing.yml');
+    }
}
```

Create a `routing.yml`, e.g. in the directory `src/AppBundle/Resources/config/routing.yml`

Put the following content:

```
app.ajax_tags:
   path: /ajax_tags/{param1}
   defaults:
       _scope: frontend
       _token_check: true
       _controller: 'AppBundle\Controller\AjaxTagsController'
```

Create the `AppBundle\Controller\AjaxTagsController.php`.

You can use  as a boilerplate.

The `__invoke()` method contains all the parameters that are mentioned in the path of the routing definition (`routing.yml`).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 92.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~110 days

Recently: every ~118 days

Total

8

Last Release

2781d ago

PHP version history (2 changes)v1.0.0PHP ^5.3 || ^7.0

v1.3.0PHP ^5.6 || ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1284725?v=4)[Richard Henkenjohann](/maintainers/richardhj)[@richardhj](https://github.com/richardhj)

---

Top Contributors

[![richardhj](https://avatars.githubusercontent.com/u/1284725?v=4)](https://github.com/richardhj "richardhj (25 commits)")[![fiedsch](https://avatars.githubusercontent.com/u/5047601?v=4)](https://github.com/fiedsch "fiedsch (1 commits)")[![fritzmg](https://avatars.githubusercontent.com/u/4970961?v=4)](https://github.com/fritzmg "fritzmg (1 commits)")

---

Tags

ajaxcontaohttpajaxcontaonetwork

### Embed Badge

![Health badge](/badges/richardhj-contao-simple-ajax/health.svg)

```
[![Health](https://phpackages.com/badges/richardhj-contao-simple-ajax/health.svg)](https://phpackages.com/packages/richardhj-contao-simple-ajax)
```

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k869.4M8.8k](/packages/symfony-http-kernel)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M339](/packages/api-platform-core)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k320.9M982](/packages/symfony-psr-http-message-bridge)[api-platform/http-cache

API Platform HttpCache component

274.6M20](/packages/api-platform-http-cache)[friendsofsymfony/http-cache-bundle

Set path based HTTP cache headers and send invalidation requests to your HTTP cache

43713.9M66](/packages/friendsofsymfony-http-cache-bundle)[contao-community-alliance/dc-general

Universal data container for Contao

1680.8k92](/packages/contao-community-alliance-dc-general)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
