echsop 购物车实现淘宝ajax效果_多一度热爱_百度空间
{dy}步 根目录common.js 在头部插入以下代码就ok

/* *
* 添加商品到购物车
*/
function addToCartbuy(goodsId, parentId)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];

// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);

if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}
}

goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);

Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponsebuy, 'POST', 'JSON');
}
function divshow()
{
document.getElementById('light').style.display='block';
}
function callback(res)
{
if (res.err_msg.length > 0)
{
alert(res.err_msg);
}
else
{

if (document.getElementById('ECS_SHOWDIV'))
{
document.getElementById('ECS_SHOWDIV').innerHTML = res.result;
//document.getElementById('ECS_SHOWDIV1').innerHTML = res.result;

}

}
divshow();
}
/* *
* 处理添加商品到购物车的反馈信息
*/
function addToCartResponsebuy(result)
{
Ajax.call('goods.php','act=recal&id=' + goodsId,callback, 'POST', 'JSON' );
if (result.error > 0)
{
// 如果需要缺货登记,跳转
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id;
}
}
// 没选规格,弹出属性选择框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id);
}
else
{
alert(result.message);
}
}
else
{

var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}

if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{

switch(result.confirm_type)
{
case '1' :
if (confirm(result.message));// location.href = cart_url;
break;
case '2' :
if (!confirm(result.message));// location.href = cart_url;
break;
case '3' :
//location.href = cart_url;
break;
default :

break;
}

}

}
}

第二步goods.dwt 在点击加入购物车的图片的下方,{zh0}是在form结束的前面插入以下代码,另外还需要将
javascript:addToCart 改为javascript:addToCartbuy //这里是调用自己写的加入购物车的函数,上次就是这里没说清楚,呵呵

<!--{if $goods.goods_number neq 0 && $goods.is_on_sale neq 0 }-->
<div id="light" class="white_content">
<table style="width:352px;">
<tr>
<td style="height:25px; border:none;padding-left:32px; padding-top:3px;" align="left">商品已经成功加入购物车!
</td>
<td align="right" style="padding-right:8px; border:none"> <a href="javascript:void(0)" onFocus="this.blur()" onclick="document.getElementById('light').style.display='none';">
</a>
</td>
</tr>
<tr>
<td colspan="2" style="border:none;">
<div id="ECS_SHOWDIV" style=" clear:both;width:300px">
</div>
</td>
</tr>
<tr >
<td ><a onFocus="this.blur()" href="flow.php">进入购物车</a>
</td>
<td>
<a href="javascript:void(0)" onFocus="this.blur()" onclick="document.getElementById('light').style.display='none';">继续购物</a>
</td>
</tr>
</table>
</div>
<!--{/if}-->

第三步,在样式表里面添加一下css


/*购物车弹出效果*/
.white_content { display: none;   position: absolute; top: {bfb}; background-image:url(images/cart_info.gif); left: 60%; overflow:hidden; width: 352px; height: 101px;       z-index:1002;    }
* html .white_content{ display: none;   position: absolute; top: 105%; background-image:url(images/cart_info.gif); left: 60%; overflow:hidden; width: 352px; height: 101px;       z-index:1002;}
*+html .white_content { display: none;   position: absolute; top: 95%; background-image:url(images/cart_info.gif); left: 60%; overflow:hidden; width: 352px; height: 101px;       z-index:1002;    }
   .white_content a{ text-decoration:none}
.cutclass{display: none;   position: absolute; background-image:url(images/share.gif);   top: {bfb};   left: 30%; overflow:hidden; width: 511px; background-color:#fff; height: 87px;       z-index:1002;}

第四步在goods.php中加入以下代码,放在

/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */

的前面
/*------------------------------------------------------ */
//-- 点击购物按钮时改变购物车信息
/*------------------------------------------------------ */
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'recal')
{
    include('includes/cls_json.php');
    $json   = new JSON;
    $res    = array('err_msg' => '');
    $res['result']=insert_cart_info();
    die($json->encode($res));
}



郑重声明:资讯 【echsop 购物车实现淘宝ajax效果_多一度热爱_百度空间】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——