M
M
malayamarisha2020-07-09 08:42:42
1C-Bitrix
malayamarisha, 2020-07-09 08:42:42

How to pass value from js to php?

Good day!
It is necessary to transfer the received value from the data-id-offers attribute to the php variable in the product card.
In the file /bitrix/templates/test/components/bitrix/catalog.element/main/script.js I set the value of the data-id-offers attribute and write it to idOffers

document.getElementById("out").dataset.idOffers = this.offers[index].ID;
var idOffers = this.offers[index].ID;

Next, idOffers must be transferred to the /bitrix/templates/test/components/bitrix/catalog.element/main/template.php file.
I do this, but in template.php $_POST is empty:
$.ajax({
 url: "/bitrix/templates/test/components/bitrix/catalog.element/main/template.php",
 type: "POST",
data: {idOffers:idOffers}

There have been attempts to do so, but in this case, the data-id-offers attribute disappears on the page:
BX.ajax.post(
url: this.ajaxURL,
type: post,
data: {idOffers:idOffers}
        );

Please tell me how to pass var idOffers = this.offers[index].ID; from script.js to template.php

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question