ECSHOP如何用JS或Ajax全站调取购物车商品总数量

2025-02-25 11:26:01
推荐回答(1个)
回答1:

自己写个ajax请求的php页面test.php:


define('IN_ECS', true);


require(dirname(__FILE__) . '/includes/init.php');


$sql = "select goods_number from ". $GLOBALS['ecs']->table('cart') . ' where user_id = '. $_SESSION["user_id"];

$number = $GLOBALS['db']->getOne($sql);

echo $number;

调用ecshop封装的ajax方法Ajax.call:

Ajax.call('test.php','',myresponse,'POST','TEXT');

function myresponse(result){
    var text = document.getElementbyId('id');
    text.val = result;
}
ajax请求test.php 得到结果result,通过回调函数赋值给id为id的元素。