406 error on ajax calls in Drupal 8
Your controller must return an array or a Response object.

If you want to return the content as-is (no "drupal" around it):

return new Response($content)


If you want to return a normal, full page, then just return the render array.