Ecshop中调用ajax

Ajax源文件js/transport.js(用于支持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));//输出
}

Leave a comment

Your comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word