Skip to content
Advertisement

How to update cart item quantitty with ajax in laravel?

I want to increment/decrement cart quantity by clicking the button. See this image preview image

This cart row is shown by forcach loop. First row is working perfectly. The problem is, when I click on the seceond/last row, I get only first row value. I don’t know how to solve that. Here is view code

JavaScript

Here is ajax code

JavaScript

Here my controller code

JavaScript

Can anyone tell me way how to solve that problem?

Advertisement

Answer

Here is the problem:

JavaScript

jQuery fetch’s the value of the first item with class .input-quantity every time because you’ve used this:

JavaScript

so you should tell it to pass the value for related item to the clicked item:

JavaScript

Also I didn’t find you’ve set id anywhere! so you can set as as an data-attribute like this:

JavaScript

then you can use this code:

JavaScript

You must consider that you’ve used class twice for an element:

JavaScript

that is absolutely wrong

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement