Learn how to identify and work with XHR requests


The \BitFrame\Message\RequestTrait provides a handy isXhr() method to check if the http request was an ajax request. For example:

if ($request->isXhr()) {
    // do something...

This is a non-PSR standards based method, and is only available on class objects that use \BitFrame\Message\RequestTrait. Default request objects created in BitFrame have this trait included automatically. The use of this helper method is strictly optional as it's merely meant as a shortcut to what you can just as easily accomplish without using it.

Under the hood the isXhr() method works by looking for the presence of the X-Requested-With HTTP request header and ensures its value is XMLHttpRequest.


Let us know if you have something to say or add