Tom*_*Tom 10 ajax jquery cakephp-2.1
最终找到了解决方案:
如果有人有这个问题,请将其放入您的前置过滤器中.
$this->Security->unlockedActions = array('givestar');
Run Code Online (Sandbox Code Playgroud)
并将库更新到Cake 2.3
问题:
我正在努力解决我的ajax调用问题上的SECURITY组件.
var id = 1;
$.ajax({
type: "post",
url: "/messages/givestar/",
data: {"id" : id},
dataType: "json"
});
Run Code Online (Sandbox Code Playgroud)
我只是试图发送控制器的ID来更新id = id的消息
但是安全组件在我所有的ajax调用中都是Blackholing.
任何人都知道如何使其与安全组件激活?
谢谢!
你太棒了!
-Tom
建议????
UPDATE2 经过一些测试后,我从黑洞得到AUTH错误.
From Book:
‘auth’ Indicates a form validation error, or a controller/action mismatch error.
Run Code Online (Sandbox Code Playgroud)
我已经仔细检查了所有ACO节点,它们很好.我在我的ajax调用中依赖于安全组件的FORM VALIDATION ERROR.
更新:
AppController.php
public $components = array(
'Acl',
'Auth',
'Session',
'Security',
'Cookie'
);
public function beforeFilter() {
$this->Security->blackHoleCallback = 'blackhole';
}
public function blackhole($type) {
$this->Session->setFlash(__('ERROR: %s',$type), 'flash/error');
}
Run Code Online (Sandbox Code Playgroud)
MessagesController.php
public $components = array('RequestHandler');
public function beforeFilter() {
parent::beforeFilter();
}
public function givestar() {
$this->autoRender = false;
if ($this->request->is('ajax')) {
echo 'Working';
}
return;
}
Run Code Online (Sandbox Code Playgroud)
在beforefilter中:
$this->Security->unlockedActions = array('givestar');
Run Code Online (Sandbox Code Playgroud)