我需要将数据发布到如下 URL:
http://www.your_domain.com/checkout/cart/add?product=68&qty=1&super_attribute[528]=55&super_attribute[525]=56
See here for Magento documentation on query string
我当前的代码看起来像这样,但它不起作用。
var myObject = {
super_attribute: {configOptionSuperAttribute: configOption}
};
jQuery.post(productAddToCartURL, { product: productId, qty: qty, super_attribute: jQuery.param(myObject) })
.done(function(data) {
alert("Data Loaded: " + data);
});
问题出在 super_atribute[] 上。如何使 myObject 兼容?
感谢您的帮助!
最佳答案
根据jQuery.param
(在内部用于序列化数据),您的数据应如下所示:
jQuery.post(
productAddToCartURL,
{product: productId, qty: qty, super_attribute: configOption},
function() { ... }
);
其中 configOption
是表单的对象
var configOption = {
528: 55,
525: 56
};
关于jQuery 使用 post 关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17224481/