Ajax Sepetin İçeriğin Anlık güncellenmesi
Merhaba Arkadaşlar
ajax kodlarım bu şekilde.
$(document).ready(function(){
$(".addToCartBtn").click(function () {
var url = "http://localhost/akeajans/include/cart_db.php";
var data = {
p : "addToCart",
product_id : $(this).attr("product-id")
}
$.post(url, data, function (response) {
$(".cart-count").text(response);
})
})
$(".removeFromCartBtn").click(function () {
var url = "http://localhost/akeajans/include/cart_db.php";
var data = {
p : "removeFromCart",
product_id : $(this).attr("product-id")
}
$.post(url, data, function (response) {
window.location.reload();
})
})
})
buda html php kodlarım.
<ul id="top_tools">
<li>
<a href="nojavascript...void(0);" class="search-overlay-menu-btn"><i class="icon_search"></i></a>
</li>
<li>
<?php
if (isset($_SESSION["shoppingCart"])) {
$shoppingCart = $_SESSION["shoppingCart"];
$total_count = $shoppingCart["summary"]["total_count"];
$total_price = $shoppingCart["summary"]["total_price"];
$shopping_products = $shoppingCart["products"];
} else {
$total_count = 0;
$total_price = 0.0;
}
// print_r($shopping_products);
?>
<?php if($total_count > 0) { ?>
<div class="dropdown dropdown-cart">
<a href="#" data-toggle="dropdown" class="cart_bt"><i class="icon_bag_alt"></i>
<strong><?php echo $total_count; ?></strong></a>
<ul class="dropdown-menu" id="cart_items">
<?php foreach ($shopping_products as $product) { ?>
<li id="licik">
<div class="image"><img src="<?php echo TEMA;?>/img/thumb_cart_1.jpg" alt="image"></div>
<strong><a href="#"><?php echo $product->adi; ?></a>
<?php echo $product->count; ?>Adet x <b><?php echo $product->fiyat; ?> ₺ </b></strong>
<a product-id="<?php echo $product->id; ?>" class="action removeFromCartBtn">
<i class="icon-trash"></i>
</a>
</li>
<?php } ?>
<li>
<div style="font-size: 10px;">Toplam Ürün: <span style="font-size: 10px;"><?php echo $total_count; ?> Adet</span></div>
<div>Toplam Fiyat: <span><?php echo $total_price; ?> ₺</span></div>
<a href="cart.html" class="button_drop">Sepetim</a>
<a href="<?php echo TEMA ?>/cikis/sepetsil/" class="button_drop outline">Boşalt</a>
</li>
</ul>
</div><!-- End dropdown-cart-->
<?php } else { ?>
<div class="dropdown dropdown-cart">
<a href="#" data-toggle="dropdown" class="cart_bt"><i class="icon_bag_alt"></i>
<strong class="cart-count"><?php echo $total_count; ?></strong>
</a>
<ul class="dropdown-menu" id="cart_items">
<li>
<p>Sepet BOş</p>
</li>
</ul>
</div>
<?php }?>
</li>
</ul>
şimdi hal böyle olunca sepete ekle diyorum sayfa yenilenmeden sepet üzerinde 1-2-3-4 kaç kere ekleyince onun rakamı çıkıyor
fakat eklediğim ürün sayfa yenilemeden listelenmiyor bunun için ne yapmam gerekiyor.
Soru hatalı mı? 👎
Eğer sorunun kurallara aykırı olduğunu düşünüyorsanız lütfen bize bildirin!
Cevaplar (0)
Henüz kimse cevap yazmadı. İlk cevap yazan sen ol!