configuration of a php cookie

0

I would like to know how to correct the following error, when I make an entry to a shopping cart I send it to a cookie through ajax with php and jquery.

view - > Ajax - > php (setcookie).

view:

<button onclick="addCar(<?php echo $p["pro_id"].",".$desc; ?>)" class="button btn-block btn-cart cart first" type="button">Añadir al Carrito</button>

ajax:
function addCar(id,desc) {
  if ($('#cantCarPro').val()!="") {
    $.ajax({
      url: 'panel/php/mod_carTemp.php',
      type: 'POST',
      data: {tipo: 1, id: id, desc: desc, cant: $('#cantCarPro').val(), tall: $('#tallCarPro').val()},
      success:function(v) {
        ////////
      }
    });
  }else{
    alert("Debe ingresar una cantidad");
  }
}

php:
setcookie("producto[".$_POST["id"]."][id]", $_POST["id"]);
setcookie("producto[".$_POST["id"]."][cantidad]", $_POST["cant"]);
setcookie("producto[".$_POST["id"]."][descuento]", $_POST["desc"]);
setcookie("producto[".$_POST["id"]."][talla]", $_POST["tall"]);

but when doing it the first time it does not work, I click again and make the entry to the cookie, thank you in advance.

    
asked by hack20858 12.03.2018 в 22:29
source

0 answers