Answer the question
In order to leave comments, you need to log in
What to add to the basket file via AJAX?
Hello. The site has a basket, you need to do it without reloading. After three days of picking, I realized that I could not do without help.
HTML code:
<form id="formCart" action="javascript:void(null);">
<input class="hitNameBasket" type="hidden" name="hitName" value="<?=$Element['NAME'];?>" />
<input class="hitPriceBasket" type="hidden" name="hitPrice" value="<?=$Element['PRICE'];?>" />
<a href="#" class="hitToBasket" data-id="<?=$Element['ID'];?>">В корзину</a>
</form>
$('.hitToBasket').click(function(e){
e.preventDefault();
var dataId = $(this).data('id');
var dataName = $('.hitNameBasket').val();
var dataPrice = $('.hitPriceBasket').val();
$.ajax({
type: 'POST',
url: '<?require_once($_SERVER["DOCUMENT_ROOT"]."/template/cart.php");?>',
data: {id: dataId},
success: $('.orderName').text(dataId),
});
});
Answer the question
In order to leave comments, you need to log in
What is this design anyway?
url: '<?require_once($_SERVER["DOCUMENT_ROOT"]."/template/cart.php");?>',
This should be a link like example.com/cart.php and not some kind of cart template.
And in this file you need to handle your $_POST.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question