我刚刚在这里建立了购物车 添加到购物车按钮可以完美地将产品添加到购物车而无需刷新整个页面。
我的问题是,如何让购物篮在点击添加到购物车链接后更新内容而不刷新页面
我有代码来处理将产品添加到购物车并显示购物车内容。
<?php
if($what=="addtocart")
{
if ($cart)
{
$cart .= ','.$_GET['product_id'];
}
else
{
$cart = $_GET['product_id'];
}
$_SESSION['cart'] = $cart;
}
echo writeShoppingCart();
?>
这里是 writeShoppingCart() 函数
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p>You have no items in your shopping cart</p>';
} else {
echo "<table class=table cellpadding=5 cellspacing=0 width=87% border=0>";
echo "<tr class=bold>";
echo "<td width=65>ID Product</td>";
echo "<td>Pattern</td>";
echo "<td>Inst Type</td>";
echo "</tr>";
include "config.php";
global $dbhost,$dbusername,$dbpassword;
$id_mysql = mysql_pconnect($dbhost,$dbusername,$dbpassword);
mysql_select_db($dbname, $id_mysql);
$cart = $_SESSION['cart'];
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
foreach ($contents as $id=>$qty) {
$view2 = "SELECT * FROM $table_product WHERE id='$id'";
$result2 = mysql_query($view2);
while
($baris=mysql_fetch_row($result2))
{
echo "<tr>";
echo "<td>$baris[1]</td>";
echo "<td>$baris[2]</td>";
echo "<td>$baris[3]</td>";
echo "</tr>";
}
}
echo "</table>";
echo "<span class=\"go_cart\">» <a href=\"cart.php\">View Complete Basket</a></span>";
}
}
echo writeShoppingCart();
将产品添加到购物车后是否有任何重新加载的线索?