B
B
Brees2019-08-05 21:53:26
1C-Bitrix
Brees, 2019-08-05 21:53:26

How to cook ajax in Bitrix?

Good afternoon, I came across an article https://avivi.pro/blog/universalnaya-ajax-podgruzk... , a very interesting implementation of ajax in Bitrix components, but I can’t understand what sessions are used for:

$_SESSION[__CLASS__][$uniqueKey] = array(
                'NAME' => $name,
                'PARAMS' => $params,
                'TEMPLATE' => $template
            );

Which then get in the Ajax handler and pass the finished html, calling the component.
$component = Universal\Ajax::getComponent($uniqueKey);
...
$APPLICATION->IncludeComponent($component['NAME'], $component['TEMPLATE'],  $component['PARAMS'], false);

Why take data from sessions if they are still transmitted in the body of the ajax request?
$.ajax({
            url: '/ajax/component.php',
            type: 'post',
            data: {
                key: ComponentKey, // ключ компонента
                name: list_data['NAME'], // имя компонента
                template: list_data['TEMPLATE'], // имя шаблона
                params: list_data['PARAMS'], //дополнительные параметры 
            },
            success: function(data) {
                $('#years').after(data);
            }
        });

Could you share some advice on how you use ajax in your Bitrix projects? Except $.ajax({src: '<?= $APPLICATION->GetCurPage() ?>'})for obvious reasons

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question