Simple Ajax call with Drupal 8


I want to add a link to my content page that will dynamically change/replace content on the page using AJAX.


The solution here is add a route and to write a call back that will respond accordingly. The only difference here is 

  • The link is not a a normal link but a link that will load using a AJAX call
  • The Response here is also not normal it will be a  AjaxResponse


So lets see how we can do this