Here is the problem:
var quantity = $('.input-quantity').val();
var id = $('.id').val();
jQuery fetch's the value of the first item with class .input-quantity
every time because you've used this:
$('.input-quantity')
so you should tell it to pass the value for related item to the clicked item:
$(document).on('click', '.qty', function(e) {
e.preventDefault();
// $(this) mentions the clicked element (target)
var quantity = $(this).val(); // trasnlate: pass the value of the clicked (target) element
....
}
Also I didn't find you've set id
anywhere! so you can set as as an data-attribute like this:
<input data-id={{ $cart->id }} type="number"
class="input-text qty text input-quantity "
step="1" min="0" name="quantity[]"
value="{{ $cart->quantity }}" title="Qty" size="4">
then you can use this code:
$(document).on('click', '.qty', function(e) {
e.preventDefault();
// $(this) mentions the clicked element (target)
var quantity = $(this).val(); // trasnlate: pass the value of the clicked (target) element
var id = $(this).attr("data-id");
....
}
You must consider that you've used class
twice for an element:
class="input-text qty text input-quantity " class="quantity"
that is absolutely wrong
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…