国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

ecshop購物車無刷新更新

2024-04-25 20:42:15
字體:
來源:轉載
供稿:網友

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購物車無刷新更新。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大城县| 南川市| 湾仔区| 江达县| 罗甸县| 枝江市| 昌黎县| 清新县| 巴塘县| 五峰| 乾安县| 介休市| 三明市| 辉南县| 肥西县| 聊城市| 柳江县| 陈巴尔虎旗| 盐池县| 屏边| 景泰县| 台安县| 彭阳县| 临安市| 静乐县| 东方市| 盐津县| 甘南县| 唐山市| 永春县| 河南省| 龙岩市| 清远市| 太康县| 商河县| 涿州市| 玉溪市| 偏关县| 巴彦县| 赣榆县| 上林县|