最新消息: 新版网站上线了!!!

Ecshop中调用ajax的方法

调用:js/common.js
以添加商品到收藏夹为例:
Goods.dwt :
<a href=”javascript:collect({$goods.goods_id})”><img src=”images/bnt_colles.gif” /></a>
function collect()
{
Ajax.call(‘user.php?act=collect’, ‘id=’ + goodsId, collectResponse, ‘GET’, ‘JSON’);
}
/* *
* 处理收藏商品的反馈信息
*/
function collectResponse(result)
{
alert(result.message);
}
处理端user.php:
/* 添加收藏商品(ajax) */
elseif ($action == ‘collect’)
{
include_once(ROOT_PATH .’includes/cls_json.php’);//载入json类
$json = new JSON();//初始化json
$result = array(‘error’ => 0, ‘message’ => ”);// 设置回传参数
$goods_id = $_GET['id'];
if (!isset($_SESSION['user_id']) || $_SESSION['user_id'] == 0)
{
$result['error'] = 1;
$result['message'] = $_LANG['login_please'];
die($json->encode($result));//输出
}

转载请注明:谷谷点程序 » Ecshop中调用ajax的方法