Hello, I'm trying to use Ajax in a form to add products to the cart without refreshing the page but I can not if someone can help me.
I'm using Laravel 5.3 based on this site :
HTML
<form id="form_ideal" action="/cart/add" method="post" name="add_to_cart">
{!! csrf_field() !!}
<input type="hidden" name="product" value="{{$product->id}}" />
<input type="hidden" name="qty" value="1" />
<span class="compr-games" title="Add to Cart"><button class="btn-add-to-cart"> Buy Now </button></span>
</form>
Script I'm trying:
<script type="text/javascript">
$('#form_ideal').on('submit', function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '/cart/add',
data: $(this).serialize(),
success: function(msg) {
swal('Test')
}
});
});
</script>
What happens is that clicking the add button to the cart shows the success message but does not update the quantity in the menu, it gets "0", it only refreshes after I give F5 on the page,
I'm sorry if I've done something wrong but I started to mess with Laravel, ajax, those things ..
Thank you