终于找到了解决方案:
如果有人遇到这个问题,请将其放入您的前置过滤器中。
$this->Security->unlockedActions = array('givestar');
并将库更新到 Cake 2.3
问题:
我正在努力解决安全组件在我的 ajax 调用中对我造成的影响。
变量id = 1;
$.ajax({
type: "post",
url: "/messages/givestar/",
data: {"id" : id},
dataType: "json"
});
我只是尝试发送 Controller 的 ID 来更新 id=id 的消息
但是安全组件在我所有的 ajax 调用中都黑洞了我。
有人知道如何让它在激活安全组件的情况下工作吗?
谢谢!
你太棒了!
-汤姆
建议???
更新2 经过一些测试后,我收到来自 blackhole 的 AUTH 错误。
From Book:
‘auth’ Indicates a form validation error, or a controller/action mismatch error.
我已经仔细检查了所有 ACO 节点,它们都很好。我在 ajax 调用中遇到来自安全组件的表单验证错误。
更新:
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');
}
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;
}
最佳答案
在过滤器之前:
$this->Security->unlockedActions = array('givestar');
关于jquery - CakePHP 2.1 在激活安全组件的情况下进行 jquery ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11869336/