【发布时间】:2021-09-30 16:28:34
【问题描述】:
我已附上代码,请检查: 如果我将数据传递给硬编码的 AJAX 函数,例如“{ 更新:{40066070315190: 0, 40067491528886: 0, 40094075945142: 0} }”,那么它工作正常,但是当我尝试使其动态并设置变体 ID 和数量通过循环然后它不会更新数据但仍会进入成功函数。
有什么问题吗?
var formData = { updates: {} };
jQuery.getJSON('/cart.js', function(thisCart, textStatus) { // Get cart items
$.each(thisCart.items, function(cartIndex, cartElement) {
if(~cartElement.title.indexOf('Build your own box')) {
formData.updates[parseInt(cartElement.variant_id)] = 0;
}
});
});
jQuery.ajax({
type: 'POST',
url: '/cart/update.js',
// data: { updates: {40066070315190: 0, 40067491528886: 0, 40094075945142: 0} },
data: formData,
dataType: 'json',
success: function(data) {
console.log('success', data);
},
error: function (request, status, error) {
alert(request.responseText);
}
});
还附加了参考的 console.log 输出 CLICK TO SEE THE CONSOLE.LOG OUTPUT
【问题讨论】:
标签: jquery ajax api shopify liquid