M
M
maksplotnikoff2017-08-30 11:09:53
PHP
maksplotnikoff, 2017-08-30 11:09:53

Ajax file upload and $arResult transfer (Bitrix)?

I'm doing a search on the site. There are 2 types of content display, grid and list. In the search.page template, I created 2 .php files, and depending on what is in the cookies, I include one of them. Switching between this display should be on ajax. How to implement all this correctly?
What I do: there is an ajax handler that, when clicked, sends me to a file in which I include one or another output template

$APPLICATION->IncludeFile(".../components/bitrix/search.page/search/".$_POST['TEMPLATE'].".php", array('arResult' => $arResult));

The only problem is that I can't figure out how to pass $arResult. After all, passing it to ajax is not a very good idea, there is a lot of information.
If the handler is sent to template.php that starts like this:
<?
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
$templateFolder = $this->GetFolder();
    if (!empty($_POST) && $_POST["ACTION"] == "ChangeSearchView") {

        $APPLICATION->IncludeFile($templateFolder."/".$_POST['TEMPLATE'].".php", array('arResult' => $arResult));
    }
?>

Then an error is displayed in the console
Fatal error: Using $this when not in object context in .../components/bitrix/search.page/search/template.php on line 3

How to do it right anyway?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2017-08-30
@babarun

1. Option: in the settings of the component "AJAX_MODE" => "Y"
2. Option: depending on the request, connect a different template for the component. You frame the component with a div into which you will load the result of the ajax call.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question