A
A
Abram3332021-11-10 10:49:47
1C-Bitrix
Abram333, 2021-11-10 10:49:47

How to reinitialize JS after submitting ajax form?

Good day to all!)
There is a pop-up feedback form on the site. It is in a component with "AJAX_MODE" => "Y". After sending it, the JS code in it stops working (For example, the form does not close, formatting in the fill fields does not work). Please tell me how can I fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Morozov, 2021-11-19
@Q_BASIC

Another option is to add this code to the footer

<script>
    BX.addCustomEvent('onAjaxSuccess', function(){
        let event = new Event("DOMContentLoaded");
        document.dispatchEvent(event);
    });
</script>

After ajax requests, events will be re-hung, as if the page had just loaded.
The link has a second option, without AJAX_MODE and without resetting events on elements
https://r-morozov.ru/bitrix/kak-sdelat-formu-v-bit...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question