我正在调用cakePhp控制器的ajax调用:
$.ajax({
type: "POST",
url: 'locations/add',
data: {
abbreviation: $(jqInputs[0]).val(),
description: $(jqInputs[1]).val()
},
success: function (response) {
if(response.status === "success") {
// do something with response.message or whatever other data on success
console.log('success');
} else if(response.status === "error") {
// do something with response.message or whatever other data on error
console.log('error');
}
}
});
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我收到以下错误消息:
控制器操作只能返回Cake\Network\Response或null.
在AppController中我有这个
$this->loadComponent('RequestHandler');
Run Code Online (Sandbox Code Playgroud)
启用.
Controller函数如下所示:
public function add()
{
$this->autoRender = false; // avoid to render view
$location = $this->Locations->newEntity();
if ($this->request->is('post')) {
$location = …Run Code Online (Sandbox Code Playgroud)