Jquery添加到购物车
我想创建一个麦卡龙的电子商务网站,用户可以选择一个固定的盒子(比如说1个盒子意味着10个麦卡龙),然后将它们添加到购物车中。因此,场景是,通过单击左侧面板中的产品(请参见屏幕截图SS1.png),相同的产品将出现在框中,依此类推。我已经通过JQuery完成了必要的工作,并且工作得很好 当用户在框中填写所需的Macaron并单击“添加到购物车”按钮时,产品将作为“集合/组”添加到购物车中。因此,购物车看起来就像第二个屏幕截图-SS2.png。您能告诉我如何将产品添加到购物车中吗?该站点位于PHP和MySQL上 屏幕截图如下所示:Jquery添加到购物车,jquery,Jquery,我想创建一个麦卡龙的电子商务网站,用户可以选择一个固定的盒子(比如说1个盒子意味着10个麦卡龙),然后将它们添加到购物车中。因此,场景是,通过单击左侧面板中的产品(请参见屏幕截图SS1.png),相同的产品将出现在框中,依此类推。我已经通过JQuery完成了必要的工作,并且工作得很好 当用户在框中填写所需的Macaron并单击“添加到购物车”按钮时,产品将作为“集合/组”添加到购物车中。因此,购物车看起来就像第二个屏幕截图-SS2.png。您能告诉我如何将产品添加到购物车中吗?该站点位于PHP和
等待您的回复。在我看来,您正在寻找
AJAX
功能
您可以编写如下代码:
我假设所选项目显示在一个div中,带有某种唯一的id
$(document).ready(function() {
$('#addtocartbutton').click(function() {
// here you can loop through the div or something to get the selected items
var quantities = {}; //creating an empty string to store the productids and quantities selected
$('selecteditemsdiv').each(function(){
var itemid = $(this).data('id');//get the item id assuming it is stored in the data-* attributes
var qty = $(this).data('qty'); //get the quantity if you have stored it in data-* attributes
just push it in the json string
quantities['itemid'] = qty;
});
$.ajax({
url: "cart.php",
type: "POST",
data: {datainfo: quantities}, //pass the json string to php
success: function(data) {
// Do stuff when the AJAX call returns
}
});
});
});
你试过使用angular js吗?我认为这将使这个应用程序更容易实现