magento2.3 – Ajax call to Controller 404’ing

I’ve created a controller within my custom module to add items to my basket and i’m trying to make an ajax call across to it. However, I can’t even call my controller currently as I get a 404 error from my ajax call.

This is how my Controller currently looks:


namespace VendorTestModuleControllerIndex;

use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionContext;

class Test extends Action

    public function __construct(
        Context $context
    ) {

    public function execute()
        return "Success";

This is the ajax call in my phtml file:

var data = "";
var addToCartUrl = "<?php echo $block->getUrl('testmodule/index/test'); ?>";

    url : addToCartUrl,
    dataType : 'json',
    type : 'POST',
    data: data,
    success : function(res)
    error : function()

Here is my routes.xml file:

<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
    <route id="test_testmodule" frontName="test_testmodule">
        <module name="Test_TestModule" />

I’ve tried to manually visit the URL that i’m sending the ajax call to and that doesn’t display anything either.