E
E
Ex1st2021-03-25 08:18:31
1C-Bitrix
Ex1st, 2021-03-25 08:18:31

How to pass arResult in ajax.php of a component?

I need to pass the element ID from the same component to the ajax.php script. The arResult array is empty. The option with sessions is not suitable, because if the user opens 2 tabs with different elements, then the ID of the last opened tab will be written to ajax.php.

What other options are there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Ex1st, 2021-03-25
@Ex1st

You can pass the element ID in AJAX:

$(document).ready(function() {
        $('#one_click_buy').submit(function(e) {
            e.preventDefault();
            $.ajax({
                type: "POST",
                url: 'component_folder/ajax.php',
                dataType: "json",
                data: {'id': <?= $arResult['PRODUCT_ID'] ?>},
                success: function(response)
                {
                    $('#OneBuyClickRX').modal('hide');
                    $('#ordersuccess').modal('show');
                }
            });
        });
    });

And then catch in ajax.php
json_decode($id);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question