php购物车不刷新,ecshop购物车无刷新更新

ecshop的购物车使用是相当的不方便.ecshop购物车一旦加入了商品,就必须点更新数量的按扭才能够更新.这样对ecshop使用者相当的不方便。我们将结合ecshop ajax的思路。来讲讲用ecshop的ajax无刷新更新购物车.

1:首先要包含js/shopping_flow.js 该文件主要是针对ecshop购买流程控制的js.我们将增加以下函数.

function submit_update_cart(rec_id){

var goods_number = document.getElementById("goods_number_"+rec_id).value;

Ajax.call('flow.php?step=ajax_update_cart', 'goods_number=' + goods_number+'&rec_id='+rec_id, submit_update_cartResponse_cart, 'GET', 'JSON');

}

2:在flow.dwt中。我们要修改input输入框.

3:在ecshop的购物车函数中。什么json来结合ecshop ajax处理更新结果.部分程序如下

include_once('includes/cls_json.php');

$result = array('error' => '', 'content' => '', 'fanliy_number' => '0', 'rec_id' => '');

$json = new JSON();

/* AJAX修改购物车 */

$rec_id   = $_REQUEST['rec_id']; //购物车ID

$goods_number   = $_REQUEST['goods_number'];//

/* 判断库存 */

$num = $db -> getOne("select g.goods_number from ".$ecs->table('goods')." g ,".$ecs->table('cart')." c where c.rec_id = '$rec_id' and g.goods_id = c.goods_id ");

if($goods_number > $num){

$goods_number = $num;

$result['error']  = 1;

$result['fanliy_number']= $num;

$result['rec_id']       = $rec_id;

$result['content']  = '该商品库存不足'.$goods_number." 件,只有".$num."件";

die($json->encode($result));

}

/* 修改商品购物车 */

$sql = "update ".$ecs->table('cart')." set goods_number = '".$goods_number."' where rec_id = '".$rec_id."' and session_id = '" . SESS_ID . "' ";

$db -> query($sql);

4:通过flow.php中的php.返回更新数量后的结果.

function submit_update_cartResponse_cart(result){

if(result.error == '1'){

document.getElementById("goods_number_"+result.rec_id).value = result.fanliy_number;

alert(result.content)

}else{

var layer = document.getElementById("xianshi_price");

layer.innerHTML = (typeof result == "object") ? result.content : result;

}

}

通过以上ecshop二次开发例子,我们最模板完成了ecshop购物车无刷新更新。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值