ecshop Ajax使用
2016-06-13 13:05 来源:www.chinab4c.com 作者:ecshop专家
cshop中的ajax非常好用,当自己第一次使用的时候,也非常吃力。当自己用多了的时候,却感觉十分简单,也特别方便。
首先,建立dwt.里面写个form进去,加个form提交时间的按扭
其次,在js中增加函数
function sub_zixun(){
var frm = document.forms['zixun_form'];
var msg_title = frm.elements['msg_title'].value;
var msg_phone = frm.elements['msg_phone'].value;
var user_email = frm.elements['user_email'].value;
var msg_content = frm.elements['msg_content'].value;
var msg = '';
if (msg_title.length == 0)
{
msg += '标题不能为空' + '\n';
}
if (msg_phone.length == 0)
{
msg += '电话号码不能为空' + '\n';
}
if (user_email.length == 0)
{
msg += 'Email不能为空' + '\n';
}
if (msg_content.length == 0)
{
msg += '评论不能为空' + '\n';
}
if (msg.length > 0)
{
alert(msg);
return false;
}
else
{
Ajax.call( 'zixun.php?act=act_sub', 'msg_phone=' + msg_phone+'&user_email='+user_email+'&msg_content='+msg_content+'&msg_title='+msg_title, act_callback , 'POST', 'TEXT', true, true );
}
}
3:增加回调函数act_callback ()
function act_callback(result){
if(result == 'true'){
alert("提交评论成功");
}else{
alert("提交评论失败");
}
}
处理ajax回调值的结果
elseif ($act == 'act_sub'){
include_once(ROOT_PATH . 'includes/lib_clips.php');
$message = array(
'user_id' => $_SESSION['user_id'],
'user_name' => $_SESSION['user_name'],
'user_email' => isset($_POST['user_email']) ? htmlspecialchars(trim($_POST['user_email'])) : '',
'msg_type' => isset($_POST['msg_type']) ? intval($_POST['msg_type']) : 0,
'msg_title' => isset($_POST['msg_title']) ? trim($_POST['msg_title']) : '',
'msg_content' => isset($_POST['msg_content']) ? trim($_POST['msg_content']) : '',
'order_id' => 0,
'msg_area' => 1,
'msg_phone' => trim($_POST['msg_phone']),
'upload' => array()
);//留言板提交的数据
if (add_message($message)){
echo 'true';
}else{
echo 'false';
}
}
这样就完成了一次ecshop中ajax的所有调用步骤。
最近更新
常用插件
- ecshop供应商插件免费下载
ecshop供应商插件免费下载...
- ecshop选择下单时间插件
ecshop选择下单时间插件主要是根据不同的下单配送要求,在ecshop购物车...
- ecshop按分类筛选销售排行
ecshop按分类筛选销售排行...
- ecshop二次开发售后维修卡
插件介绍: 本插件是用于专门从事电子,信息,软件等售后服务关键比...
- ecshop快递发货单打印商品
ecshop快递发货单打印商品信息,大家都知道ecshop快递单打印的时候,只能...