TYPO3 v11.5前端Ajax路由404问题求助
TYPO3 v11.5 后端AJAX接口404问题排查求助
开发环境与扩展结构
参照TYPO3 v11.5官方后端AJAX教程开发扩展,扩展目录结构如下:
├── Classes │ └── Controller │ └── ExampleController.php ├── Configuration │ ├── Backend │ │ └── AjaxRoutes.php │ └── Services.yaml ├── Resources │ ├── Private │ │ └── Templates │ │ └── test.html │ └── Public │ └── JavaScript │ └── Calculate.js ├── composer.json ├── ext_emconf.php └── ext_localconf.php
关键配置代码
1. Configuration/Backend/AjaxRoutes.php
<?php use (privacy)\ajaxcool\Controller\ExampleController; return [ 'myextension_example_dosomething' => [ 'path' => '/ajaxcool/do-something', 'target' => ExampleController::class . '::doSomethingAction', ], ];
2. ext_localconf.php
<?php $GLOBALS['TYPO3_CONF_VARS']['FE']['ajaxRoutes']['myextension_example_dosomething'] = [ 'path' => '/ajaxcool/do-something', 'target' => (privacy)\ajaxcool\Controller\ExampleController::class . '::doSomethingAction', ];
前端请求代码
因无法使用require,改用fetch编写请求脚本:
const baseUrl = 'https://ajax-typo3-test3.ddev.site/'; const inputNumber = 5; fetch(`${baseUrl}/ajaxcool/do-something?input=${inputNumber}`, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => console.log(data)) .catch(error => console.error('Error:', error));
问题现象
执行请求后报错:Calculate.js:29 Error: Error: Network response was not ok,直接访问URL https://ajax-typo3-test3.ddev.site/ajaxcool/do-something?input=5 也显示404页面不存在,请求排查问题原因。
内容的提问来源于stack exchange,提问作者bwfront
相关产品推荐
相关产品推荐

