Author Topic: Refresh cart content  (Read 671 times)

0 Members and 1 Guest are viewing this topic.

Offline DarkPrince2005Topic starter

  • Enthusiast
  • Posts: 295
  • Gender: Male
    • View Profile
Refresh cart content
« on: March 16, 2010, 05:20:51 AM »
Ok peeps...

This is my code:
Code: [Select]
<div style="position:relative;top:60px;font-size:9px;">now in your cart:
<?php 
if($_SESSION['customCartCount'] > 0){echo $_SESSION['customCartCount'];} else { echo "0"; } ?>
items.</div>

It returns the count of cart items stored in the session. The problem is it only gets updated once the page is reloaded. Is there any way I can update and display it periodically without having to reload the page?
There is a solution to every problem, but that solution isn't always easily found. But being persistent helps

Offline solon

  • Enthusiast
  • Posts: 214
  • Gender: Male
    • View Profile
    • MK Web Design & Development | Cyprus Web Design
Re: Refresh cart content
« Reply #1 on: March 17, 2010, 04:46:59 AM »
You can create a jquery function that loads the result in the div you want.

it would be something like the following:
Code: [Select]
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> //Include the jQuery Library
    <script type="text/javascript">
function load_cart(x) // Create your function with a value to recognize who's cart is it... lets say the customer id value as a parameter
{
  $('#cart').load('cart_cont.php',{                                    //#cart is the id of the div (or any element) you want to load the result
   s_id : x                                                                      //s_id:x - s_id is the value you will get with $_POST['s_id']; in your php file
   });                                                                             //x is the parameter you send to the function when calling it i.e. load_cart(2)
}                                                                                  //cart_cont.php should have your php code that returns the result
</script>
Solon
MK Web Design & Development Ltd
http://www.mkwebcy.com
http://www.backup-easy.com