I’m trying to update the users cart, when on the /cart page, without triggering a page reload.
In my template I have a button
<a
onclick="minusOne(event, '{{ routes.cart_change_url }}?line={{ item_index }}&quantity={{ item.quantity | minus: 1 }}')">
Minus One
</a>
And then I have a javascript function
function minusOne(event, args){
// these seem to have no effect
event.preventDefault()
event.stopPropagation()
console.log(args)
// /cart/change?line=1&quantity=1
$.post({
url:args,
})
}
The above, and the many other things I’ve tried in the past few days, always change the cart but cause the page to reload. I’d like to take care to update the UI myself.
An example where I’ve seen this successfully implemented is https://insulation4less.co.uk/cart
I’ve tried https://cartjs.org/ with no success. Maybe I did it wrong, or maybe it doesn’t offer what I thought it did, specifically on the /cart page.
Some clarification would be very appreciated.