Подскажите как выполнить ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • m.poliit
    Junior Member
    • Jun 2023
    • 11

    Подскажите как выполнить ajax

    Мои действия,
    В файле client/src/views/site/footer.js добавил
    Code:
    Espo.Ajax.getRequest('CustomController/test')
    .then(response => {
    console.log(response);
    });


    создал файл custom/Espo/Custom/Controller/CustomController.php
    Code:
    <?php
    
    namespace Espo\Custom\Controller;
    
    use Espo\Core\Templates\ListTemplate;
    
    class CustomController extends ListTemplate
    {
    
    public function testAction()
    {
    print_r('ok');
    }
    }​
    в файле custom/Espo/Custom/Resources/routes.json
    Code:
    [
    {
    "route": "/CustomController/test",
    "method": "get",
    "params": {
    "controller": "CustomController",
    "action": "test"
    }
    }
    ]​
    в результате получаю https://loc.domain/api/v1/CustomController/test 404 (Not Found)

    Подскажите что не так делаю?
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    Hi,

    getActionTest
    class CustomController

    PHP Code:
    
    {
            "route": "/CustomController/Test/:id",
            "method": "get",
            "params": {
                "controller": "CustomController",
                "action": "test",
                "id": ":id"
            }
        },class CustomController
    {
        private $config;
        private $entityManager;
        private $log;
    
        public function __construct(Config $config, EntityManager $entityManager, Log $log)
        {
            $this->config = $config;
            $this->entityManager = $entityManager;
            $this->log = $log;
        }
    
       public function getActionTest(Request $request, Response $response)
        {
            $id = $request->getRouteParam('id'));
          
        }​​ 
    
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    Working...