I have a shopping cart in Codeigniter in which products are added to the cart using (jQuery) Ajax. In the header of each page it displays the number of contents in the cart using
<?php echo $this->cart->total_items(); ?>
How can I update/refresh this variable when a product is added to the cart, as I am using AJAX to add products to the cart and thus the page isn’t being reloaded when products are added. It seems pointless to use AJAX to do asyncronous stuff if I have to reload the page to get the new number of total items from the server.
Many thanks.
You should be able to do this by making the element containing the Shopping Card Item Count easily addressable by JavaScript, so:
Then, as part of the AJAX Function you perform, have the response contain the revised value for the total items, and then have your function replace the content of this span with that value.