gpt4 book ai didi

jquery - CakePHP 的 AJAX POST 请求导致 400 响应(黑洞)

转载 作者:太空宇宙 更新时间:2023-11-03 13:09:18 26 4
gpt4 key购买 nike

我刚刚将 SSL 添加到运行 Cake 2.3.8 应用程序的 Ubuntu 12.04 apache2 服务器。我确保在每次通话前添加 https://... 并使用 grep 确认。据我所知,没有被阻止的脚本。当我尝试使用 AJAX 将来自 JS 文件的 AJAX 发布请求发送到我的服务器时,我收到类似

的错误
The request has been black-holed
Error: The requested address '/sorts/available_spaces' was not found on this server.

在我发出 POST 请求的 JS 文件中

$.post("https://www.mywebsite.com/sorts/available_spaces",{'customerID' : self.customerID, 'arrivalDate' : self.arrivalDate},function(data) {
data = JSON.parse(data);
for(i=0;i<data.length;i++){
self.roomNumberList.push({spaceNumber: data[i].spaceNumber, roomID: data[i].roomID});
}
});

在我的 SortsController 中,我什至尝试将访问控制源设置为允许一切并禁用安全性(暂时),但我仍然收到黑洞请求

//SortsController

var $components = array('Security');

public function beforeFilter(){
$this->response->header('Access-Control-Allow-Origin', '*');
$this->Security->unlockedActions = array('available_spaces', check_reservation');
$this->Auth->allow('available_spaces','check_reservation');
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
parent::beforeFilter();
}

即使在 available_spaces 方法中,也不会调用其他方法或 SortsController 之外的任何内容。我的 Sort 模型中没有任何内容,我的 AppController 中根本没有调用安全性。

这是堆栈跟踪。除了路由之外,我什至没有看到 SortsController 或方法的提及。

 CORE/Cake/Controller/Component/SecurityComponent.php line 241 → SecurityComponent->blackHole(SortsController, string)
[internal function] → SecurityComponent->startup(SortsController)
CORE/Cake/Utility/ObjectCollection.php line 132 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 248 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 675 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 184 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 162 → Dispatcher->_invoke(SortsController, CakeRequest, CakeResponse)
APP/webroot/index.php line 118 → Dispatcher->dispatch(CakeRequest, CakeResponse)

最佳答案

预计通过 Ajax 发布的帖子将无法在启用安全组件的情况下使用。

根据 http://whatswhat.no/development/framework/cakephp-2/465-making-a-jquery-ajax-call-with-security-component-activated-in-cakephp-2您需要将您的操作添加到安全组件的解锁操作中:

public function beforeFilter() {
parent::beforeFilter();
$this->Security->unlockedActions = array('ajax_action');
}

关于jquery - CakePHP 的 AJAX POST 请求导致 400 响应(黑洞),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20410381/

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