Ajax-Call mit einer Route will nicht klappen
Hallo,
ich hab in meinem Bundle eine routing.yml unter:
mycontao/vendor/georgpreissl/imagefilter/src/Resources/config/routing.yml
... mit folgendem Inhalt:
Code:
test:
path: /test
defaults:
_controller: 'Imagefilter\Controller\ImagefilterController::loadAction'
_scope: frontend
_token_check: false
Dazu noch den Controller unter:
mycontao/vendor/georgpreissl/imagefilter/src/Controller/ImagefilterController.php
... mit folgendem Inhalt:
Code:
<?php
namespace GeorgPreissl\Imagefilter;
use Contao\CoreBundle\Exception\PageNotFoundException;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\FilesModel;
use Contao\StringUtil;
use Contao\Validator;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\JsonResponse;
class ImagefilterController extends Controller
{
/**
* @Route("/test/")
*/
public function loadAction(): Response
{
$objArticleModel = \ArticleModel::findByPk(1);
$title = $objArticleModel->title;
return new JsonResponse($title);
}
}
Und das Javascript im Backend-Template dazu:
Code:
$('[type=radio]').click(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "/test",
success: function(data) {
console.log('data: ',data);
},
error: function(msg) {
console.log(msg);
}
});
});
... dennoch weigert sich der Ajax-Call beharrlich zu funktionieren :rolleyes:
Ich bekomme bei dem Klick auf den Radio-Button in der DevTools-Console einen:
Code:
VM527:1 POST http://mycontao/test 404 (Not Found)
Kann mir jemand sagen/schreiben was ich hier falsch mache?
Bitte um eure Hilfe – vielen Dank im Voraus.