I have problem here, I need all the stuffs inside this $_SESSION['cart'] thing
and pass it to jQuery to use it in a php-ajax file, my question is, how to do that?
Here’s what I have in mind
function myfunc()
{
//save cart to db of logged user
$("a.savecart").click(function(){
//how to assign the $_SESSION['cart'] into a js variable ?
$.ajax({
type: "POST",
url: "classes/ajax.cart.php",
data: //what to put here ?
success: function(data){
alert(data);
location.reload();
}
});
return false;
}
});
}
Just echo it like below (just example):
Or if your
$_SESSION['cart']is an associative array, you can usejson_encodefunction.EDIT:
For example, if your
$_SESSION['cart']is an array like below:Then in your php ajax part, you could get the data by
$_POST['id']and$_POST['num']etc…