M
M
MaxEpt2021-02-02 12:53:50
1C-Bitrix
MaxEpt, 2021-02-02 12:53:50

How to work with BX.ajax.runAction correctly?

I'm trying to use Bitrix controllers for ajax request to my module via BX.ajax.runAction.

At the root of the module is .settings.php with the following content:

<?
return [
    'controllers' => [
        'value' => [
            'namespaces' => [
                '\\Petrov\\Main\\Controller' => 'mapi',
            ],
        ],
        'readonly' => true,
    ],
];


The module itself is in the local folder, the name is petrov.main, inside the lib folder -> controller -> BasketActions.php, its code
<?
namespace Petrov\Main\Controller;

use Bitrix\Main\Engine\Controller;

class BasketActions extends Controller
{
    public function configureActions()
    {
        return [
            'getAnalogs' => [
                'prefilters' => []
            ]
        ];
    }

    /**
     * @param $arXmlId
     * @return array
     */
    public function getAnalogsAction($arXmlId)
    {
           return [];       
    }
}


Call from js like this:
BX.ajax.runAction('petrov:main.mpi.BasketActions.getAnalogs', {data:{}});


The project is deployed locally - everything works as it should. Uploaded to the server - I get the error
Could not find description of mapi.BasketActions.getAnalogsAction in Bitrix\\Main\\Engine\\DefaultController

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxEpt, 2021-02-03
@MaxEpt

The solution is in the comments, the problem was in the naming of the controller file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question