Jump to content

Refresh cart content


DarkPrince2005

Recommended Posts

Ok peeps...

 

This is my code:

<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?

 

Link to comment
Share on other sites

You can create a jquery function that loads the result in the div you want.

 

it would be something like the following:

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.