S
S
Stalker_darkway2015-12-11 04:09:09
PHP
Stalker_darkway, 2015-12-11 04:09:09

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>

AJAX code:
$('.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),
    });
  });


Now the ID is passed to .orderName, but it disappears when the page is reloaded.
I don't see what print_r($_POST); Empty array.
AJAX links to cart.php
What should be in this file? What is the logic? Where to dig? If possible, in more detail.
Thank you very much in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-12-11
@hronik87

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.

S
Sergey, 2015-12-11
@gangstarcj

Here is an example for Bitrix for NOT programmers) there is only one meaning, you can take it as a basis

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question