我需要將數據上傳到像這樣的URL:使用jQuery的崗位關聯數組
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兼容?
感謝您的幫助!
'configOption'的價值是什麼?它是一個數組還是對象?它看起來怎樣?數據使用'jQuery.param'(http://api.jquery.com/jQuery.param/)進行序列化。查看文檔以瞭解如何構建對象。 –
當你說「它不工作」時,你是什麼意思?您是否收到JavaScript錯誤?電話是否到達服務器?完成的回調沒有被解僱? – Jacob
你真的在你的代碼中使用了'jQuery.param'嗎?或者剛纔我提到它?你不應該明確地調用它,它由jQuery在內部調用來序列化整個數據對象。更新中的'myObject'在我的回答中看起來像'configOption'。不要讓它比它更復雜;) –