Ajax is not working in cart using Gloudeman/ShoppingCart. Ajax was giving me alerts at first but when I complete the code ajax was not adding products to cart. It just moves to the top of the page.
index.blade.php
@php $countP=0; @endphp @forelse($sarma->chunk(20) as $chunk) @foreach($chunk as $sarmas) <input type="hidden" id="prod_id<?php echo $countP;?>" value=""/> <figure class="item "> <div class='product product-style-3'> <div class='img-wrapper'> <a id="" class='js-quick-view products' href="#" type='button' data-toggle='modal'data-target='#quick-view-product'> <img class='img-responsive' src="" alt='productthumbnail'> </a> <div class="product-control-wrapper bottom-right"> <div class="wrapper-control-item"> <a class="js-quick-view" href="#" type="button" data-toggle="modal" data-target="#quick-view-product"> <span class="lnr lnr-eye"></span> </a> </div> <div class="wrapper-control-item item-add-cart"> <a class="animate-icon-cart" href="#"> <span class="lnr lnr-cart" id="addCart<?php echo $countP;?>) "> </span> </a> </div> </div> </div> <figcaption class="desc"> <h3> <a class="product-name" href="#"></a> </h3> <span class="price">PKR. </span> </figcaption> </div> </figure> @php $countP++; @endphp @endforeach </div> </div>@endforelse
This is the ajax I am using in below of the code.
Ajax
<script> $(document).ready(function(){ <?php $maxP = count($sarma); for($i=0; $i<$maxP; $i++){ ?> $('#addCart<?php echo $i; ?>').click(function () { var prod_id<?php echo $i; ?> = $('#prod_id<?php echo $i; ?>').val(); alert(prod_id <?php echo $i;?>); $.ajax({ type: 'get', url: '<?php echo url('/cart/add-item'); ?>/'+prod_id<?php echo $i; ?>, success: function () { alert('done') } }); }); <?php } ?> }); </script>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire