0

I have several products. On click product, I send "id" of clicked product to Local Storage. To use this variable in php I send it to items.php ($.post).

Then I need use this "id" from items.php to show in the cart, but variable is emply.

var LSArray = JSON.parse(localStorage.getItem('productID')) || [];

function clickOnProduct(id) {
    var newItem = {'id': id};
    LSArray.push(newItem);

    localStorage.setItem("productID", JSON.stringify(LSArray));
    var dataLS = JSON.parse(localStorage.getItem('productID')) ;

    $.ajax({
                type : "POST", 
                url  : "/wp-content/themes/twentynineteen/items.php", 
                data : { name : dataLS[dataLS.length-1].id },
                success: function(res){  
                    console.log(res);
                }
        });
}

All works fine, but how can I use "id"?

<?php incude(items.php); ?> 

dosn't work.

kompaniietst
  • 250
  • 3
  • 10

1 Answers1

-1

You are sending it by post. So you can take a look to your post variable by

<?php var_dump($_POST); ?>

Then you will see the array and probably you can access your data by $_POST['name']

Juan
  • 463
  • 5
  • 10