分类分类
更新时间:2026-05-11 00:59:45作者: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购物车无刷新更新。
相关
修真情缘角色扮演303.33 MBv1.0.02026-05-10
下载我的小独角兽女孩休闲益智380.89 MBv1.0.232026-05-10
下载超级种田男孩手机版经营养成1.31Gv1.0.92026-05-10
下载不必要的实验冒险游戏64.9 MBv1.1.592026-05-10
下载军师联盟策略游戏163.2 MBv0.0.12026-05-10
下载翻天喜地凑大钱手机版休闲益智138.72 MBv1.0.92026-05-10
下载东离剑游纪手游动作射击1.6Gv1.4.22026-05-10
下载天猫养车商家版App学习办公74.95 MBv0.6.12026-05-10
下载掌上命运方舟App手游辅助137.48 MBv1.9.12026-05-10
下载退役军人服务APP生活服务67.16 MBv1.2.52026-05-10
下载屯漫漫画APP资讯阅读23.06 MBv2.0.32026-05-10
下载蛋仔派对蛋壳App手游辅助185.73 MBv0.0.22026-05-10
下载









