Skip to content

Instantly share code, notes, and snippets.

@renebakx
Last active February 18, 2016 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renebakx/7a31fe1a852f144e3c2e to your computer and use it in GitHub Desktop.
Save renebakx/7a31fe1a852f144e3c2e to your computer and use it in GitHub Desktop.
A very basic Drupal 8 AJAX repsonse

router.yml :

simple_twitter.ajax_controller_get_tweets:
  path: '_simple_twitter/tweets/{name}/{number}'
  defaults:
    _controller: '\Drupal\simple_twitter\Controller\AjaxController::getTweetsForUserAction'
    _title: 'getTweetsForUser'
  requirements:
    _permission: 'access content'

AjaxController.php :

  public function getTweetsForUserAction($name, $number = 2){
  // some service stuff that fills $results..
    $results = $this->requestTwitterAndCache($params, $url, $cid);
    return new JsonResponse($results);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment