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
https://forums.phpfreaks.com/topic/195409-refresh-cart-content/
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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.