Answer the question
In order to leave comments, you need to log in
How to make a "add to cart" button with Ajax in 1C Bitrix?
Good day,
There is a store , in the catalog.section there are buttons "add to cart"
<a href="/catalog/<?=$arElement["IBLOCK_SECTION_ID"]?>/?<?=$arParams["ACTION_VARIABLE"]?>=ADD2BASKET&id=<?=$OFFERS['ID']?>" class="btn btn-primary buy_button" rel="nofollow" onclick="return addToCart(this, 'list', '<?=GetMessage("CATALOG_IN_CART")?>', 'noCart');" id="catalog_add2cart_link_<?=$OFFERS['ID']?>"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> В корзину</a>
Answer the question
In order to leave comments, you need to log in
See the implementation in the standard template. It describes the functions of adding ajax, but if you have a highly custom directory it will be difficult.
I usually redo the standard template and check that the standard button works, which is difficult to achieve, because by deleting some id, it no longer works.
Another such way
<button style='width:100%; margin:5px auto;' class="product__btn btn btn--bg-green btn--color-white" type='submit' onclick="$.post('?action=ADD2BASKET&ajax_basket=Y&id=<?=$arItem["ID"]?>&quantity=1', function(data) {
if (data.STATUS == 'OK'){
BX.onCustomEvent('OnBasketChange');
}
});">
В корзину
</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question