Thursday 15 May 2014

php - Update cart with ajax -



php - Update cart with ajax -

hi i've made eshop , want accomplish when click appropriate "add cart button" want top cart (not main cart-page of eshop) updated. top cart 1 div @ header of eshop. when refresh page right content appears doesn't happen without refresh. know must accomplished ajax seems doing wrong.

part of code:

<input type="button" class="add_to_cart" id="add_to_cart" value="buy" /> <script type="text/javascript"> $('input.add_to_cart').click(function () { $.ajax({ type: "post", url:"add_to_topcart.php", data:$('.prod_form').serialize(), success:function(data){ $('#show-quick-cart').text(data); $(".add_cart_msg").delay(250).fadein("slow").delay(2000).fadeout("slow"); } }); }); </script> </form> </div> <div class="add_cart_msg" style="display:none;"><img src="images/green_tick.png"/>product added cart!</div>

the above has result temporarily count products add together cart

first of all, enclose code in document ready handler -

$(document).ready(function() { $('input.add_to_cart').click(function () { $.ajax({ type: "post", url:"add_to_topcart.php", data:$('.prod_form').serialize(), success:function(data){ $('#show-quick-cart').text(data); $(".add_cart_msg").delay(250).fadein("slow").delay(2000).fadeout("slow"); } }); }); });

then open browser's console , errors logged. can prepare them 1 @ time or post them here if need help troubleshooting.

php jquery ajax

No comments:

Post a Comment