In modern Bitrix correctly display in the popup window, component, result of the AJAX request?

Forced to ask the question to the world community, because the support Bitrix parellal not help, referring to the particular solution (2363153 in modern BEADS correctly to show in the popup window, component, result of the AJAX request?).

Have at the entrance of heavy component 2.0 (the other is now not used). A fresh main and ui. Need to request its issuance and show the popup window. And better (since about Bitrix speech) means BX.

Standard method (very old) - use of components in AJAX mode. Unfortunately, you quickly find documentation on the issue could not. There is an old file (it wrote). But its not invest here.
He generally is not suitable (not in order it for subsequent communication and updates only part of the page).

Well, the solution from the developers:
  • Bring the component in normal mode, but in a hidden block (and then show a script). This option is not suitable for this task - component heavy and the results not always needed.
  • To write a separate PHP script. To do so under its own template. About this is described here.


In the second case, BX.ajax comes into force the configuration settings request, processData, scriptsRunFirst and emulateOnload.

New is controllers AJAX. But this idea is closer to the REST, because it focused on the exchange of JSON.

Maybe I missed something?
March 23rd 20 at 19:31
2 answers
March 23rd 20 at 19:33
Solution
Decided on the basis of \CMain::ShowAjaxHead. Of course, documentation on it does not. Found in the source code.
Task output the scripts and styles caused by the components it solves.

Dashed your AJAX script that calls any component. Opposed to new ideas Bitrix (AJAX controls) in the HTML and not the JSON response.

Also did my loaded JS library (used BX.ajax.promise and BX.ajax.submitAjax).
March 23rd 20 at 19:35
From novelties we have controllers AJAX. But this idea is closer to the REST, because it focused on the exchange of JSON.


It is a very interesting tool. Using it is very easy to write ajax requests to components. In the body of the JSON response you can send and HTML, passing it to one of the parameters as a simple string.

In fact, for the ajax requests to your component, you just have:
  1. The component class implement the interface Controllerable
  2. Methods that needs to respond to ajax requests should have the action suffix
  3. Client-side you need to use BX.ajax.runComponentAction


It's very simple.

Video on youtube to which you referred, there is an article https://verstaem.com/ajax/new-bitrix-ajax/ .

Personally, I'm over by the BX.ajax.runComponentAction do your wrap to you in one place to catch the same error messages and uniformly handle the response.
You are in a controller action, I repeat (cause) executeComponent and pack the results into a string?
And how give in the results list of scripts and styles? - mavis_Rodrigu commented on March 23rd 20 at 19:38

Find more questions by tags 1C-BitrixAJAX