You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 00:47:04