A
A
Anatoly Kirsanov2019-06-07 14:52:24
1C-Bitrix
Anatoly Kirsanov, 2019-06-07 14:52:24

How to correctly show in a pop-up window a component received by an AJAX request in modern Bitrix?

Forced to ask a question to the world community, because. Bitrix support did not want to help, referring to the particularity of the solution (2363153 How in a modern BUS to correctly show a component received by an AJAX request in a pop-up window?).

We have a heavy component 2.0 at the input (the others are not used now). Also available fresh main and ui. You need to request its issuance and show it in a pop-up window. And better (since we are talking about Bitrix) by means of BX .

A typical way (very ancient) is to use the component in AJAX mode. Unfortunately, I could not quickly find documentation on the issue. There is an ancient file (it was still written then). But don't include it here.
It does not fit here at all (not for this, it is for subsequent interaction and updating only part of the page).

Well, solutions from the developers:

  • Display the component in normal mode, but in a hidden block (and then show it with a script). This option does not fit the conditions of the task - the component is heavy, and the output is not always needed.
  • Run a separate PHP script. Make a separate site template for it. It's roughly described here .


In the second case, the processData, scriptsRunFirst, and emulateOnload request configuration options take effect on BX.ajax.

Of the novelties there are AJAX controllers . But this idea is closer to REST, because aims to exchange JSON.

Maybe I missed something?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly Kirsanov, 2019-06-28
@bitrixworkshop

Solved based on \CMain::ShowAjaxHead. Of course, there is no documentation for it. Found in source.
It solves the task of displaying scripts and styles of the called component.
I dashed off my AJAX script that calls any component. Difference from the new Bitrix idea (AJAX controllers) in HTML, not JSON response.
I also made my own loadable JS library (used BX.ajax.promise and BX.ajax.submitAjax).

R
Roman Gritsuk, 2019-06-08
@winer

Of the novelties there are AJAX controllers. But this idea is closer to REST, because aims to exchange JSON.

This is a very interesting tool. With it, it is very easy to write ajax requests to your components. In the body of the JSON response, you can also pass HTML by passing it as a regular string as one of the parameters.
In fact, for ajax requests to your component, you just need:
Everything is very simple.
According to the youtube video you linked to, there is an article https://verstaem.com/ajax/new-bitrix-ajax/ .
Personally, I make my own wrapper over the BX.ajax.runComponentAction method so that I can catch error messages in the same place and process the response in the same way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question