gpt4 book ai didi

jquery - CakePHP 2.1 在激活安全组件的情况下进行 jquery ajax 调用

转载 作者:行者123 更新时间:2023-12-03 22:21:59 26 4
gpt4 key购买 nike

终于找到了解决方案:

如果有人遇到这个问题,请将其放入您的前置过滤器中。

$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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com