Here's the view
<a href="{{$cart_items->contains('id',$productItem->id) ? route('IndexCart'): route('AddToCart')}}" class="item_add" id="{{$productItem->id}}"><p class="number item_price {{$cart_items->contains('id',$productItem->id) ? 'added': ''}}">
<i> </i>${{$productItem->price}}
</p>
</a>
So I need to reload current page after 2nd click on it
trying this:
$(document).ready(function(c) {
$('.item_add').click(function (event) {
var addButton = $(this).children('p');
if(addButton.hasClass('added'))
{
linktocart.attr('onclick','location.reload(true)');
}
else
{
event.preventDefault();
var id = $(this).attr('id');
var href = $(this).attr('href');
var data = {'cart_item_id': id};
var carturl = "http://site.loc/cart";
$.ajax({
url: href,
data: data,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: 'POST',
dataType: 'JSON',
success: function (html) {
addButton.addClass('added');
addButton.css('background', 'green');
addButton.parent('a').attr('href', carturl);
$('#addOrAlready').text('Added');
}
});
}
});
It doesn't work, I guess, because I prevented default when I clicked it 1st time, so I think I need to "un"prevent default to make reload before going to link work. How can I do it? I need it because i guess chrome loads cached copy of page which hasn't applied changes on server.
尝试处理mousedown事件而不是单击。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.