title: Restrict routes to a Ajax call, it's possible in Symfony 2.6+?
body: <p>I'm looking the best way to achieve "automatic" routing restriction to Ajax calls. Right now I'm doing as follow:</p>
  
  <pre><code>/**
   * @Secure(roles="IS_AUTHENTICATED_FULLY")
   * @Route("/someRoute", name="someRoute")
   * @Method("POST")
   */
  public function eliminarFacturasAction(Request $request)
  {
      $response['success'] = false;
      $status              = 400;
  
      if ($request-&gt;isXmlHttpRequest()) {
          // needs to set $response values and $status=200 all the time
      } else {
          // needs to handle the exception and return Json response
      }
  
      return new JsonResponse($response, $status ?: 200);
  }
  </code></pre>
  
  <p>In order to avoid this could I use this instead?</p>
  
  <pre><code> @Route("/someRoute", 
             name="routeName", 
             condition="request.headers.get('X-Requested-With') == 'XMLHttpRequest'"
   )
  </code></pre>
  
  <p>I'm using jQuery as only JS framework so <code>XMLHttpRequest</code> wont be a problem. What kind of exception will be trigger if route isn't executed through Ajax call? Can I catch it and show message to users? Or show some kind of 404 page? </p>
  
  <p>I have found a similar question <a href="https://stackoverflow.com/questions/11557658/is-it-possible-to-restrict-a-route-for-ajax-only">here</a> but is not clear for me at all</p>