简体   繁体   English

将项目添加到购物车AJAX Laravel

[英]Add items to shopping cart AJAX Laravel

I'm using Laravel for ecommerce website and adding items by this way: 我将Laravel用于电子商务网站并通过以下方式添加项目:

<div class="product-icon-container">
    <a href="{{ route('product.addToCart', ['id' => $product->id]) }}"><i class="fa fa-shopping-cart"></i></a>
</div>

Can you suggest AJAX solution to adding items to cart without refreshing page? 您能提出AJAX解决方案来添加商品到购物车而无需刷新页面吗?

You can capture onclick and submit asynchronously with Jquery . 您可以捕获onclick并使用Jquery异步提交。

<script type="text/javascript">
        $('.product-icon-container').find('a').click(function (event){
            event.preventDefault();
            $.ajax({
                url: $(this).attr('href')
                ,success: function(response) {
                    alert(response)
                }
            });
            return false; //for good measure
        });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM