I found lots of articles that suggest to use your extension for ajax requests.
My actual use case is to mark a news as being read via an ajax call. I'm using the extension mediadreams/md_unreadnews which contains a controller action for that. They have a view helper that calls the controller action which is meant to be included on the news detail page. I need ajax, because I have no detail page. Instead all news are loaded before and an entry is displayed with javascript.
I generated following URLs in my page template:
<script>
[
'<t:uri.ajaxAction pluginName="Unread" controller="Unreadnews" action="removeUnread" />',
'<t:uri.ajaxAction extensionName="MdUnreadnews" pluginName="Unread" controller="Unreadnews" action="removeUnread" />',
'<t:uri.ajaxAction extensionName="Mediadreams.MdUnreadnews" pluginName="Unread" controller="Unreadnews" action="removeUnread" />',
].forEach(url => {
$.post(url).then(resp => console.log(url, resp));
})
</script>
I removed the first one, because it will produce an error:
Argument 1 passed to Helhum\TyposcriptRendering\Uri\TyposcriptRenderingUri::buildTypoScriptRenderingConfiguration() must be of the type string, null given
The required arguments pluginName
and controller
make sense for me. However it confuses me that most of the resources found on the web don't pass those arguments.
Requests to URLs 2 and 3 respond with a complete page HTML, although I temporarily edited the controller action to throw an error on the first line. I also set a debug breakpoint at the first line and therefore can see that the action is not called.
Next, I registered a plugin and implemented a controller in my own site package extension and tried to call that with ajax. The result is the same.
ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'my_site_package',
'Unread',
[
\MySitePackage\Controller\UnreadnewsController::class => 'removeUnread'
],
// non-cacheable actions
[
\MySitePackage\Controller\UnreadnewsController::class => 'removeUnread'
]
);
.../my_site_package/Resources/Private/Templates/Page/Default.html
<t:uri.ajaxAction extensionName="my_site_package" pluginName="Unread" controller="Unreadnews" action="removeUnread" />
<t:uri.ajaxAction extensionName="MySitePackage" pluginName="Unread" controller="Unreadnews" action="removeUnread" />
Typo3 11.5.9
helhum/typoscript-rendering 2.4