Cart total not updating when changing quantity with AJAX

Hello,

I’ve an issue regarding the cart total which does not update when I’m updating an item quantity using Ajax. Basically, I’m changing the quantity of an item based on the user cart content. I’ve attached my code below. The update is reflect in the cart subtotal only when I refresh the page. Correct me if I’m wrong but the goal of using the AJAX request is to not have the page reload right ? So why when the request returns a successful response the cart total is not updated as it should and I still need to reload the page ?

I’ve noticed that the response of the request contains the correct cart informations. But it seems that I need to reload the cart page for the information to be displayed. What can I do to prevent this behaviour an have the updated cart displayed once ?

Thank you !

if (( cartItems.length >= 1 ) && (counter > 1)){
     
       let multiplier = 2 + counter
      cartUpdates = { {{ variant_id }}: multiplier}
       var params = {
      type: 'POST',
      url: '/cart/update.js',
      data: { updates: cartUpdates },
      dataType: 'json',
      success: function(response) {        
      let disp = multiplier*1.99
        for (let j=0;  j

Hi @Abbab

Hope you’re having a great day!

A closing ‘}’ is missing at the end. Fix it and try again.

If you have any further questions, please do reach out either here on the forum, or via a private message/email.

Hello @Morek

Thanks, for your response ! I’ve recheck my code and now it’s working. The problem, is that I wasn’t updating the quantity fields in the cart page after getting the response of the Ajax request. I’ve correct that and everything works !

hello could you tell me how to add code to change the quantity in cart, then cart can automatically update?

i use minimal theme , but if i want to change quantity in my cart, then the total price never changed

could you kindly help me?

Hi @Abbab

Hope you’re having a great day!

You’re welcome. Always happy to help.