adamccol Posted June 30, 2014 Share Posted June 30, 2014 Hi, Yes I know, I CC3! But anyway, I have modified the POST request in the viewProd.tpl with a JQuery call: - function submitForm() { $.ajax({type:'POST', url: '{CURRENT_URL}', data:$('#addBasket').serialize(), success: function(refreshCart) { xxWHAT JAVASCRIPT TO GO HERE?xx }}); } The post request works fine, but I am really stuck on is what javascipt to enter in the success function to update the cart details at the top of my page one the post has completed. If I enter the template HTML, I am missing the qty and cart total variables. (As a temporary measure, I have inserted "location.reload();" but this cleary defeats the object of using AJAX!) I know this is a really old version of cubecart, but I'm sure this will be really easy for some of you old-handers out there! You can see my site at www.toyday.co.uk/toydaytest Thanks - I look forward to hearing from you. Adam Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 30, 2014 Share Posted June 30, 2014 The answer depends on what the POST response actually is: a complete div-block, or just a list (xml-formatted?) of items, prices, and totals. If a complete div block, then whatever code that processes the ajax POSTed data will need to render the skin's template file /boxes/shoppingCart.tpl. Then echo that rendered HTML to the expecting ajax response. The ajax call success function will put the HTML in the <div class="txtCart"> innerHTML. (Depending on the skin, jQuery may need to find the <div class="boxTitleRight"> and replace the entire div, not just the innerHTML.) If just a list, then you will need to parse the list and update the various <span> and <a> nodes. This will probably involve editing the teplate code to make the <span>'s have an id attribute to identify what is what. Quote Link to comment Share on other sites More sharing options...
adamccol Posted June 30, 2014 Author Share Posted June 30, 2014 Hi, Thank you Bsmither for your prompt reply. The block I need to return is indeed a DIV block. whatever code that processes the ajax POSTed data will need to render the skin's template file /boxes/shoppingCart.tpl This is where I am stuck! Do I somehow need the function to re-write the same html as in the shopping cart tpl file? If so, I do not know how to get the cart variables from the cart to insert into my HTML Hmm, I do apologise, Although ok with PHP, HTML and MYSQL, I really struggle with javascipt! I am tempeted to buy Sir Williams mod for V4, and hope that i can figure out how it will fit with my ancient and heavily modified V3.14. (And no, upgrading is not an option!) Thanks again... Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 30, 2014 Share Posted June 30, 2014 Considering this is CubeCart 3 (and, technically, no longer supported on these forums), allow me to suggest we continue this discussion in the CC3 forum at www.cubecartforums.org, or by email. "Do I somehow need the function to re-write the same html as in the shopping cart tpl file?" I would say yes, but in the POST (or in the URL querystring), we need to identify this page request as being an ajax request. Then, we modify the code that processes the shoppingcart template to test for the ajax identifier and to echo the rendered contents and exit PHP. Quote Link to comment Share on other sites More sharing options...
adamccol Posted July 2, 2014 Author Share Posted July 2, 2014 bsmither, I can not thank you enough. You pointed me in the right direction to add the code I need to get it working. Just for completeness, and in case it might just help anyone else, here is the code I added to the include/ShoppingCart.inc.php //Admic - return cart data to AJAX POST if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo "<div class='carttext'> <a class='carttext' href='http://www.toyday.co.uk/shop/cart.php?act=cart' alt='Click to checkout' title='Click to checkout'><span class='basketQty'>".$cart->noItems()."</span><b>My Basket: </b>£".$cartTotal."</a></div>"; die($content); } bsmither, if you ever find yourself in Cornwall, UK, I would very much like to buy you a beer or two. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.