A
A
Alexander2020-06-01 15:46:41
1C-Bitrix
Alexander, 2020-06-01 15:46:41

How to return the result of the component to a variable?

On the side of the ajax.php file, the sale.basket.basket.linetmp component (basket) is processed,
then the ajax file returns the result of the work in the form of html, and this html is added to the layout block on the frontend side.

ajax.php file code

define('STOP_STATISTICS', true);
define('NOT_CHECK_PERMISSIONS', true); 

if (!isset($_POST['siteId']) || !is_string($_POST['siteId']))
  die();

if (!isset($_POST['templateName']) || !is_string($_POST['templateName']))
  die();

if ($_SERVER['REQUEST_METHOD'] != 'POST' ||
  preg_match('/^[A-Za-z0-9_]{2}$/', $_POST['siteId']) !== 1 ||
  preg_match('/^[.A-Za-z0-9_-]+$/', $_POST['templateName']) !== 1)
  die;

define('SITE_ID', $_POST['siteId']);
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
if (!check_bitrix_sessid())
  die;

$_POST['arParams']['AJAX'] = 'Y';

$APPLICATION->RestartBuffer();
header('Content-Type: text/html; charset='.LANG_CHARSET);
$APPLICATION->IncludeComponent('bitrix:sale.basket.basket.linetmp', $_POST['templateName'], $_POST['arParams']);

It is necessary that the ajax file return json, since in addition to layout it is required to return several more basket parameters and it is easier to do this in one request, the result of the operation of the sale.basket.basket.linetmp component must be saved to a variable. Tell me how can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Technique102, 2020-06-01
@Technique102

If it's fast, then copy the component to your namespace. And in your class.php or component.php file, output $arResult.
Or you can leave the template empty, and display $arResult in component_epolog.php as an option.
But I wouldn't do that. It's better to write a handler without using a component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question