我想(add_cart.php?action=add&id=".$item[$i]['id'].")."
将此选择表单的结果加载到 div 中,但仍将变量传递给页面将add_cart.php
页面加载add_cart.php?action=add&id=".$item[$i]['id']."
到 div 中而不刷新但让页面执行操作。
编码:
print("<div id='add_cart'></div>
<form action='/add_cart.php?action=add&id=".$item[$i]['id']."' method='post'>
<select name='id' class='select'>
<option selected='selected' value='".$sku[$s]['id']."'>".$sku[$s]['id']."</option>
<option value='".$sku[$s]['id']."'>".$sku[$s]['id']."</option>
</select>
<input type='submit' class='add_cart' value='".$lang['add_cart']."'>
</form>
");
add_cart 代码:
session_start();
if(isset($_POST['id'])) {
$id = $_POST['id'];
}else{
$id = $_GET['id'];
}
$id_user = $_GET['id_user'];
$cart = $_SESSION['cart_order'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$id;
} else {
$cart = $id;
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart = $newcart;
break;
}