2010-01-22 94 views

回答

17
  • 您需要启用RequestHandler组件

var $components = array('RequestHandler');

  • 然后您检查您的控制器,如果一个Ajax请求:

$this->RequestHandler->isAjax()

你可以找到更多关于的信息RequestHandler component here

3

不使用的组件,你可以使用这样的事情:

 
$this->params['isAjax']; 

这将返回一个bool。

1

如果您只是想检查PHP端的功能,请尝试:

$this->log('some debug',LOG_DEBUG); 

然后检查应用程序的/ tmp /日志/的debug.log。

9

这个问题是一个老之一,但以防万一有人遇到这样和我一样,使用的CakePHP 2:

RequestHandler::isAjax()已过时,使用Request对象的$this->request->is('ajax');

更多信息here

2

这是我描述的方式是doc.I一直在使用,因为我开始使用cakephp

if($this->RequestHandler->isAjax()){ 
// 
} 
48

取决于蛋糕的版本。

的1.3.x:

$this->RequestHandler->isAjax(); 

2.x的

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

发现在谷歌的SIR这个答案。 – 2012-08-31 08:08:34