0

I am frustrated. I'm unable to add an ajax route in Magento 2.2 no matter what I try, I get a 404.

routes.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="schematics" frontName="schematics">
            <module name="Schematics" before="Magento_Adminhtml" />
        </route>
        <route frontName="schematics_ajax" id="schematics_ajax">
            <module name="Schematics" before="Magento_Adminhtml"/>
        </route>
    </router>
</config>

The Controller is beside working controllers at [module path]/Controller/Adminhtml/Ajax/Index.php and looks something like this:

//namespace is defined here.
class Index extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
        die('foo');
    }

    public function execute()
    {
        die('foo');
    }
}

/admin/schematics_ajax/index shows a 404

I'm pretty sure I followed https://devdocs.magento.com/guides/v2.2/extension-dev-guide/routing.html pretty much exactly. What am I missing?

2
  • try /admin/schematics_ajax/ajax
    – fmsthird
    Mar 29, 2019 at 17:44
  • check if it works
    – fmsthird
    Mar 29, 2019 at 17:49

1 Answer 1

0

The following fixed it and got the route standing

<?xml version="1.0"?>      
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">      
   <router id="admin">      
      <route id="schematics" frontName="schematics">      
          <module name="Schematics" before="Magento_Adminhtml" />      
      </route>      
      <route frontName="ajax" id="ajax">      
          <module name="Schematics"/>      
      </route>      
   </router>      
</config>      

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.