分类分类
更新时间:2026-04-09 16:35:58作者:fang
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输入框.<input type="text" name="goods_number[{$goods.rec_id}]" id="goods_number_{$goods.rec_id}"
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购物车无刷新更新。
相关
傲视神魔传手游策略游戏13.55 Mv1.0.02026-04-09
下载三国志王道天下策略游戏2.18Gv0.9.8.12026-04-09
下载风云三国手机版策略游戏213.99 M2026-04-09
下载星之海手机版角色扮演2.78Gv1.1.598772026-04-09
下载迪士尼梦幻王国经营养成79.34 Mv11.5.0h2026-04-09
下载TapAim动作射击97.92 Mv2.0.12026-04-09
下载肖邦大冒险九游版策略游戏133.64 Mv1.02026-04-09
下载放松时光与你共享Lo-Fi故事休闲益智951.66 Mv1.4.62026-04-09
下载羽毛球对决体育竞技175.66 Mv4.12026-04-09
下载假面骑士泽兹变身模拟器休闲益智51.91 Mv1.00.302026-04-09
下载餐车厨师烹饪游戏苹果版模拟游戏327.2 Mv8.682026-04-09
下载最终幻想7永恒危机ios版角色游戏1.5Gv3.6.02026-04-09
下载










