XHR

When using a Javascript framework like MooTools or jQuery to execute an XMLHttpRequest, the XMLHttpRequest willusually be sent with a X-Requested-With HTTP header. The Slim application will detect the HTTPrequest’s X-Requested-With header and flag the request as such. If for some reason an XMLHttpRequest cannotbe sent with the X-Requested-With HTTP header, you can force the Slim application to assume an HTTP requestis an XMLHttpRequest by setting a GET, POST, or PUT parameter in the HTTP request named “isajax” with a truthy value.

Use the request object’s isAjax() or isXhr() method to tell if the current request is an XHR/Ajax request:

  1. <?php
  2. $isXHR = $app->request->isAjax();
  3. $isXHR = $app->request->isXhr();