I did that Tutorial from the TYPO3 Page v11.5:
https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/Backend/Ajax.html
First of all my Extention Tree:
├── 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
My AjaxRoutes:
<?php
use (privacy)\ajaxcool\Controller\ExampleController;
return [
'myextension_example_dosomething' => [
'path' => '/ajaxcool/do-something',
'target' => ExampleController::class . '::doSomethingAction',
],
];
My ext_localconf.php
<?php
$GLOBALS['TYPO3_CONF_VARS']['FE']['ajaxRoutes']['myextension_example_dosomething'] = [
'path' => '/ajaxcool/do-something',
'target' =>
(privacy)\ajaxcool\Controller\ExampleController::class . '::doSomethingAction',
];
In the bottom of this TYPO3 Tutorial Page is a JS Tutorial there i get an Error because i cant use require in the frontend. So i thought i can use fetch so i wrote that Script:
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));
That didn't work.
Calculate.js:29 Error: Error: Network response was not ok
I thought i can just use my Browser and check if i can find that Url.
https://ajax-typo3-test3.ddev.site/ajaxcool/do-something?input=5
Error:
404
Page Not Found
The page did not exist or was inaccessible. Reason: The requested page does not exist
I hope u know what i did wrong and that you can Help me, Thanks!