Colorbox - Colorbox中打开的购物卡,在更新时,在相同的Colorbox中提交

时间:2013-01-12 00:58:58

标签: php jquery colorbox

我有一个带有购物车按钮的PHP商店页面。点击购物车按钮后,将在Colorbox中打开购物车表单。我希望能够更新项目/删除该Colorbox表单中的项目,并在提交后使用相同的Colorbox - 或者至少关闭前一个并打开一个新的。最后,关闭Colorbox后,确保store.php将刷新,以便购物车中的商品数量更新。

所以 - 说了这么多。我有:

store.php(有一个包含添加到购物车按钮的所有项目的表格。如果添加,它会创建一个会话“cart”变量,用于存储id和与该id相关联的项目数。然后有只有一个指向在Colorbox中打开的购物车的链接:

... ...

echo '<div style="float:right; padding-right:25px;">
<a style="outline:0;" class="gallery" href="shoppingcart.php"><img style="width:55px;     padding-left:75px;" src="/images/scart.png"></img></a><br/>
<span style="font-size:.75em;">You have ' . $cart->countItems() . ' in your shopping cart.</span>
</div>';

... ...

<SCRIPT type="text/javascript">
  $(document).ready(function(){
     jQuery('a.gallery').colorbox();    
  });    
</SCRIPT>

然后在shoppingcart.php:

<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/product.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/products.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/table.inc.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/cart.php');
$page_title = 'Shopping Cart';
include($_SERVER['DOCUMENT_ROOT'].'/includes/header2.html');
$cart = new Cart();
if (isset($_POST['do'])) {
    if ($_POST['do'] == 'remove') {
        $cart->removeProduct($_POST['product_id']);
        echo "SL:KJFSL:KJ";
    }
}
$items = $cart->getItems();
$count = $cart->countItems();
$table = new table ("100%", "tableclass", "", "");
$table->addrow
(
    new table_row
    (   
        array
        (
            new table_cell ("Product", "", "table_header", "", true),
            new table_cell ("Quantity", "", "table_header", "", true),
            new table_cell ("Price", "", "table_header_price", "", true),
            new table_cell ("", "", "table_header", "", true)
        ),
        "rowheaderclass"
    )
);


foreach($items AS $productID => $quantity) {

    $product = new Product($productID);

    $subtotal = $quantity * $product->getPrice();

    $productCell = "<form action='shoppingcart.php' method='post'>
                    <input type='hidden' name='product_id' value='{$productID}' />
                    {$product->getName()}";
    $quantityCell = "<input type='text' name='quantity' size='2' value='{$quantity}' />";
    $buttonCell = "<input type='submit' class='button' name='submit' value='Update Quantity' /></form>";
    $button2Cell = "<form id='removeForm' action='shoppingcart.php' method='post'>
                    <input type='hidden' name='do' value='remove' />
                    <input type='hidden' name='product_id' value='{$productID}' />
                    <input type='submit' class='button' name='submit' id='removeButton'
                    value='Remove from Cart' /></form>";

    $table->addrow
    (
        new table_row
        (   
            array
            (
                new table_cell ($productCell, "", "cellcenter", "", false),
                new table_cell ($quantityCell, "", "cellcenter", "", false),
                new table_cell ($subtotal, "", "cellcenter", "", true),
                new table_cell ($buttonCell, "", "cellcenter", "", false),
                new table_cell ($button2Cell, "", "cellcenter", "", false)

            ),
            "rowclass"
        )
    );

}
echo $table->get();
?>
<SCRIPT type="text/javascript">
    $(document).ready(function() {
    jQuery("input#removeButton").colorbox();



    });
</SCRIPT>

我试过的其他编码:

 function OpenNewWindow(){
    alert("test");
    parent.jQuery.colorbox.close(); 
    alert("midtest");
    parent.jQuery.colorbox({href: "/shoppingcart.php"});
    alert("posttest");
} 
$("input#removeButton").click(function ()
{
    alert("click");
    OpenNewWindow();
    alert("click2");
});

0 个答案:

没有答案