0

我希望能够在不创建 ajax 文件夹和 action.ctp 文件的情况下查看 ajax 结果。我正在使用dereuromark Ajax 组件

我已经按照以下配置了应用程序。但我仍然收到 500 错误来创建 ajax 文件夹和 action.ctp 文件。

  1. 添加$middlewareQueue->add(\Ajax\Middleware\AjaxMiddleware::class);到 Action.php 中间件
  2. RequestHandler在 AppController 中设置

    $this->loadComponent('RequestHandler', [
            'enableBeforeRedirect' => false,
        ]);
    $this->loadComponent('Ajax.Ajax');
    
  3. 我的控制器动作

    $content = ['id' => 1, 'title' => 'title'];
    $this->set(compact('content'));
    $this->set('_serialize', ['content']);
    
  4. ajax 请求正在运行,并且我能够以 json 格式获取结果。

这是我得到的错误:

{
"error":null,
"content":null,
"message":"Template file \"Delegate\/Units\/ajax\/action.ctp\" is missing.",
"url":"\/delegate\/action.json",
"code":500,
"file":"Delegate\/Units\/ajax\/action.ctp",
"line":1565,
"_message":null
}

有什么方法我不需要创建 ajax 文件夹并创建操作视图即可通过 ajax 布局查看结果。

4

0 回答 0