【问题标题】:After Append Product` add to cart` is not working追加产品`添加到购物车`后不起作用
【发布时间】:2018-04-28 12:54:02
【问题描述】:

我的div如下

<li>
  <a data-id="'.$row_p[0].'" data-name="'.$row_p[3].'" data-summary="'.$row_p[3].'" data-price="'.$row_p[6].'" data-quantity="1" data-image="'.$row_p[12].'" class="add-cart">
  <span class="icon flaticon-shopping66 "></span>
  </a>
</li>

add-cart 上点击关注函数调用(这是一个现成的插件,可以很容易地显示购物车。

    $('.add-cart').myCart({
          classCartIcon: 'my-cart-icon',
          classCartBadge: 'my-cart-badge',
          classProductQuantity: 'my-product-quantity',
          classProductRemove: 'my-product-remove',
          classCheckoutCart: 'my-cart-checkout',
          affixCartIcon: true,
          showCheckoutModal: true,
          clickOnAddToCart: function($addTocart){
            goToCartIcon($addTocart);
          },
          clickOnCartIcon: function($cartIcon, products, totalPrice, totalQuantity) {
            console.log("cart icon clicked", $cartIcon, products, totalPrice, totalQuantity);
          },
          checkoutCart: function(products, totalPrice, totalQuantity) {
            console.log("checking out", products, totalPrice, totalQuantity);
          },
          getDiscountPrice: function(products, totalPrice, totalQuantity) {
            console.log("calculating discount", products, totalPrice, totalQuantity);
            return totalPrice;
          }
        });
But Now the problem is i am using load more jquery Which Load Data On Scroll `$(window).scroll(function()..`  So on scroll i am showing Div As Following

    $.ajax({
        url: 'ajax-load-subcat.php',
        type: 'post',
        data: {row:row,idsubcat:idsubcat},
        beforeSend: function() {
          $("#dataload").show();
        },
        success: function(response){
          $(".post:last").after(response).show().fadeIn("fast");
          $("#dataload").hide();
        }
    });

所以在附加 Dive 之后,add-cart 函数也关闭了。表示它没有响应。那么当我滚动并加载数据时如何重新启动我的购物车。

我搜索了很多。但他们没有解决我的问题。谢谢。

【问题讨论】:

  • 使用$(".post:last").after(response).show().fadeIn("fast")后如何启动add-cart功能?表示我附加 div 后我的产品未添加到购物车
  • 给我发消息我的脸书我帮你在你的电脑上facebook.com/mr.jarves
  • 您已在加载新商品后重新初始化购物车。
  • 我怎么能@BugHunter
  • @MadCoder,在ajaxSuccess中叫你addCart方法

标签: javascript php jquery simplecart


【解决方案1】:

ajax 成功后再次尝试初始化 add-class/add-cart 函数

$.ajax({
    url: 'ajax-load-subcat.php',
    type: 'post',
    data: {row:row,idsubcat:idsubcat},
    beforeSend: function() {
      $("#dataload").show();
    },
    success: function(response){
      $(".post:last").after(response).show().fadeIn("fast");
      $("#dataload").hide();
      //Re-intiallize Function
      $('.add-cart').myCart({
         ....
      });
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 2014-11-21
    • 2023-03-10
    相关资源
    最近更新 更多