2017 © Pedro Peláez
 

contao-bundle contao-simple-ajax

More control over your AJAX requests.

image

richardhj/contao-simple-ajax

More control over your AJAX requests.

  • Friday, January 12, 2018
  • by richardhj
  • Repository
  • 4 Watchers
  • 5 Stars
  • 626 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 7 % Grown

The README.md

SimpleAjax for Contao Open Source CMS

Description

v1.1.0 introduces the SimpleAjax\Event\SimpleAjax. You will be 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., (*1)

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., (*2)

You simply have to register your class/method and the extension will call your class if there is an incoming ajax request. You simply have to decide if it's an ajax request for your module and return the data you want., (*3)

There are a few things you should know about the extension: * YOU have the full control over the response. That also means that you have to set the correct header. * When not setting a Response, YOU have to terminate the request after you have send the response. If the ajax request is not for your method you simply have to return nothing., (*4)

Usage

Per Event

At first: Listen on the event SimpleAjax\Event\SimpleAjax using one method described here., (*5)

Either: Set a Response

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

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)

// 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;
       }
   }
}

The Versions

12/01 2018

v1.3.x-dev

1.3.9999999.9999999-dev

More control over your AJAX requests.

  Sources   Download

LGPL-3.0+

The Requires

 

The Development Requires

ajax http contao network

12/01 2018

v1.3.0

1.3.0.0

More control over your AJAX requests.

  Sources   Download

LGPL-3.0+

The Requires

 

The Development Requires

ajax http contao network

05/10 2017
07/08 2017
02/08 2017

v1.2.0

1.2.0.0 http://www.leo-unglaub.net

More control over your AJAX requests.

  Sources   Download

LGPL-3.0+

The Requires

 

The Development Requires

ajax http contao network

27/07 2017

dev-feature/symfony-response

dev-feature/symfony-response http://www.leo-unglaub.net

More control over your AJAX requests.

  Sources   Download

LGPL-3.0+

The Requires

 

The Development Requires

ajax http contao network

03/01 2017

v1.1.0

1.1.0.0 http://www.leo-unglaub.net

More control over your AJAX requests.

  Sources   Download

LGPL-3.0+

The Requires

 

ajax http contao network

07/10 2016

v1.0.0

1.0.0.0 http://www.leo-unglaub.net

More control over your AJAX requests.

  Sources   Download

LGPL-3.0+

The Requires

 

ajax http contao network