国产探花免费观看_亚洲丰满少妇自慰呻吟_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購物車無刷新更新。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北票市| 罗山县| 贵南县| 海盐县| 常熟市| 罗源县| 南平市| 上虞市| 武川县| 辰溪县| 凤庆县| 云龙县| 确山县| 济阳县| 芦山县| 正阳县| 金坛市| 沙湾县| 汕头市| 香河县| 洪江市| 福贡县| 杂多县| 收藏| 乳山市| 五指山市| 嘉定区| 莱芜市| 商水县| 万安县| 昭平县| 定远县| 手游| 平度市| 吉林市| 万州区| 鞍山市| 大新县| 长宁县| 双柏县| 甘洛县|