weixin_33694172 2015-02-12 09:11 采纳率: 0%
浏览 26

Magento用ajax清空购物车

I am currently trying to empty the whole cart in mangento 1.9 while clicking an item. The code is in the list.phtml from my template.

<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="POST" name="emptyTheCart">
            <?php echo $this->getBlockHtml('formkey'); ?>
            <button type="submit" name="update_cart_action" value="empty_cart" style="display:none" title="<?php echo $this->__('Empty Cart'); ?>" id="empty_cart_button"></button>
      </form>

$('.item').click(function() {
    var dataExecURL = "<?php echo $this->getUrl('checkout/cart/updatePost') ?>";
         var datafiles=$("#emptyTheCart").serialize();
          $.ajax({
                type : 'POST',
                data : datafiles,
                url  : dataExecURL



            });
});

when i click on an item, it should empty my cart. Can someone please help? I do not have any clues why this is not working at all.

  • 写回答

2条回答 默认 最新

  • weixin_33720452 2015-02-12 09:31
    关注

    Add id="#emptyTheCart" to the form, since you are using $("#emptyTheCart").serialize() but the form doesn't seem to have any id?

    Other than that, your code looks correct.

    评论

报告相同问题?