【发布时间】:2019-05-01 14:36:21
【问题描述】:
我在 Shopify 中遇到问题。
我想使用 ajax 更新按钮点击时的购物车数量,但它会给出类似的错误
{"status":404,"message":"购物车错误","description":"找不到变体"}
这是我的 ajax 代码,
$('.adjust-plus').click(function(){
var qty = $(this).parent('.button-wrapper').siblings('.input-wrapper').children('.quantity').val();
var varient = $(this).parent('.button-wrapper').siblings('.input-wrapper').children('.quantity').attr('data-id');
jQuery.ajax({
type: 'POST',
async: false,
url: '/cart/update.js',
data: { updates: { varient : qty } },
dataType: 'json',
success: function() { location.href = '/cart'; }
});
});
目前两个变量的值都来了,所以值没有任何错误。
但是当 id 添加如下代码:
$('.adjust-plus').click(function(){
var qty = $(this).parent('.button-wrapper').siblings('.input-wrapper').children('.quantity').val();
var varient = $(this).parent('.button-wrapper').siblings('.input-wrapper').children('.quantity').attr('data-id');
jQuery.ajax({
type: 'POST',
async: false,
url: '/cart/update.js',
data: { updates: { 15082896588867 : 2 } },
dataType: 'json',
success: function() { location.href = '/cart'; }
});
});
然后购物车更新成功。
【问题讨论】:
-
将帖子发送到 js 文件没有意义。
标签: javascript jquery shopify shopify-template