How to get sidebar-Cart to expand after successfully adding goods?

yumaorourou
New Member
1 0 0

I created an Add to Cart button. After the goods are added successfully, there is no item in the shopping cart and it needs to be refreshed. Besides, the sidebar-Cart will not be expanded

this is code:

<script type="text/javascript">
 $(document).ready(function(){ 
   $("#section-{{ section.id }} input[type='radio']").each(function(){
     $(this).click(function(){
        var data=$(this).attr("data-variant")
        var imgurl=$(this).attr("data-image-url")
        var url = imgurl.replace(/_{width}x/ig, '')
       $(this).parents(".ProductItem__Wrapper").next().attr("id",data)
       $(this).parents(".ProductItem__Info").prev().children().children().eq(1).attr("data-srcset",url)
       $(this).parents(".ProductItem__Info").prev().children().children().eq(1).attr("srcset",url)
     })
   })
function addItemToCart(variant_id, qty) {
    var data = {
      "id": variant_id,
      "quantity": qty
    }

    $.ajax({
      type: 'POST',
      url: '/cart/add.js',
      data: data,
      dataType: 'json',
      success:function() { 
        location.reload();
        alert("Thank You! The Product Was added to the Cart Successfully.");
      }
    });
}


$('#section-{{ section.id }} .yyz-button-btn').each(function(){
     $(this).click(function(){ 
         addItemToCart($(this).attr("id"),$(this).attr("quantity"));
        
     })
   
   })
}); 
</script>
Replies 0 (0)