I am trying to get the id
of the button when its clicked process it through AJAX like shown in index.php and just echoing it out simply.
Howevr when I do that PHP tells me that postid is an undefined index
. What's the problem here please?
As I am new to AJAX I am following this youtube video.
Index.php:
<button type='submit' id=8 onclick='addToCart(this.id)'></button>
function addToCart($id) {
var idStored = $id; //When the button is clicked it passes the id. Even .val() wouldn't work
$.post('../Cart.phtml',{postid:idStored}, function(data){
window.alert(data); //Just for testing and conforming the code runs.
});
}
CartPage.php:
<?php
$name = $_POST['postid'];
echo $name;
?>
Many thanks, any help or guidance would be great.