How to check an Ajax request in cakephp? How to check an Ajax request in cakephp? ajax ajax

How to check an Ajax request in cakephp?


Depends on the version of cake.

1.3.x:

$this->RequestHandler->isAjax();

2.x || 3.x

$this->request->is('ajax');


  • You need to enable the RequestHandler component

var $components = array('RequestHandler');

  • Then you check if its an ajax request in your controllers with:

$this->RequestHandler->isAjax()

You can find more information about the RequestHandler component here


this question is an older one but just in case anyone comes across this like me and uses CakePHP 2:

RequestHandler::isAjax() is deprecated, use the Request Object's $this->request->is('ajax');

More info here