js方法实现ecshop加入购物车功能
function addToCart(goodsId,spec_id){ var goods = new Object(); var spec_arr = new Array(); var fittings_arr = new Array(); var number = 1; var formBuy = document.forms['ECS_FORMBUY']; var quick = 0; //var spec_id = $j('#spec_key_' + goodsId).attr('spec_id'); spec_arr.push(spec_id); goods.quick = quick; goods.spec = spec_arr; goods.goods_id = goodsId; goods.number = number; goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId); jQuery.ajax({ type : 'POST', url : "flow.php?step=add_to_cart", data : 'goods=' + JSON.stringify(goods), dataType : 'json', success : function(result){ //result = JSON.decode(result); result = evalJSON(result); if (result.error > 0){ alert("加入购物车失败"); } else{ $(".j_header_cart_number").html(result.goods_number); } } }); }