我创建了一个按钮"清除所有", 它将数据发送到' data.php'点击按钮通过ajax
</head>
<body>
<script type="text/javascript">
function klick(id){
$.ajax({
type:"POST",
url:"data.php",
data:{id:id},
success:function(resp){
$('#w3').html(resp);
}
});
}
</script>
<a href="shop.php">shop</a>
<br><br>
<button type='button'onclick= " klick()"/>clear all</button>
</body>
</html>
这是我的data.php页面, 所以我想做的是用空数组覆盖$ _SESSION [&#39; warenkorb&#39;]如果来自调用的变量出现在&#34; data.php&#34;页。
这样的事情:$_SESSION['warenkorb']=array();
<html>
<head>
<title>DATA</title>
<script src="https://www.novastorm.de/js/jquery-1.11.3.min.js"></script>
</head>
<body>
<?php
include 'produkte.php';
if(!isset($_SESSION['warenkorb'])){
$_SESSION['warenkorb']=array();
}
if(isset($_POST['id'])){
foreach($a as $key =>$value){
if($value['id']==$_POST['id']){
$_SESSION['warenkorb'][]= $_POST['id'];
}
}
}
print_r(count($_SESSION['warenkorb']));
?>
</body>
</html>