通常,进行ajax调用非常简单。您只需解锁控制器中的操作,并在函数中指定您使用ajax:
public function beforeFilter(Event $event) {
parent::beforeFilter($event);
$this->Auth->allow(['checkUsername']);
$this->Security->unlockedActions =['checkUsername'];
}
public function checkUsername() {
$this->request->allowMethod(['ajax']);
// ...
}
不幸的是,在CakePHP 3中,这给了我下面的黑洞错误作为回应:
code: 400
message: "The request has been black-holed"
url: "/users/checkUsername.json"
它的工作方式与它的/ users / checkUsername相同(而不是.json,这是其他地方推荐的解决方案)。有什么想法吗?
答案 0 :(得分:1)
在CakePHP 3.0中它应该是:
public function beforeFilter(Event $event) {
parent::beforeFilter($event);
$this->Auth->allow(['checkUsername']);
$this->Security->config('unlockedActions', ['checkUsername']);
}