let idElements = 147504;
let countElements = 1;
const request = new XMLHttpRequest();
request.open('POST', '<?=SITE_TEMPLATE_PATH?>/ajax/addtobasket.php');
request.responseType = 'json';
var data = JSON.stringify({"id": idElements, "count": countElements});
request.addEventListener('readystatechange', () => {
if (request.readyState === 4 && request.status === 200) {
console.log(request.response);
}
});
request.send(data);
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
if (CModule::IncludeModule("sale") && CModule::IncludeModule("catalog")) {
if (isset($_POST['id']) && isset($_POST['count'])) {
$PRODUCT_ID = intval($_POST['id']);
$QUANTITY = intval($_POST['count']);
Add2BasketByProductID( $PRODUCT_ID, $QUANTITY );
}
else { echo "Нет параметров"; }
}
else { echo "Не подключены модули"; }
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
BX.ajax({
url: '<?=\CUtil::jsEscape(SITE_TEMPLATE_PATH)?>/ajax/addtobasket.php',
method: 'POST',
data: {"id": idElements, "count": countElements},
dataType: 'json',
async: true,
onsuccess: BX.delegate(function (response) {
}, this),
onfailure: BX.delegate(function () {
}, this)
});
$request = \Bitrix\Main\HttpApplication::getInstance()->getContext()->getRequest();
if($request->isPost() && isset($request['id']) && isset($request['count'])) {
}