php - Update Cart count with AJAX success - WordPress -
in custom wordpress theme, placed cart icon in header.php
, other things placed in <li class="user-cart">
. placed db query within <li>
, "add cart" button i'm trying reload <li>
can query again , show updated count of products added.
on ajax success can using:
success: function (data) { $('.user-cart').load(window.location.href + ' .user-cart'); }
when i'm clicking on add cart button, it's reloading <li>
update count()
, it's taking <li>
within parent <li>
, like:
<li class="user-cart"> <li class="user-cart"> <a href="/view-cart"><span class="user-cart-icon"></span> 15</a> </li> <!-- cloned li --> </li> <!-- parent or original li -->
but part that, cloned <li>
loads once, on first click after page reload, count comes within second <li>
.
what's wrong part in code? don't want duplicate <li>
— want reload <li class="user-cart">
.
you should try this
success: function (data) { $('.user-cart').load(window.location.href + ' .user-cart a'); }
p.s what response data
contain? prefer use update count, without making additional request server
Comments
Post a Comment