ecshop实现ajax的tab切换效果

2,090次阅读
没有评论

js函数:

function setAjaxTab(name,cursel,n,act,id){
var target=document.getElementById("con_"+name+"_"+cursel);
Ajax.onRunning=function(){
	target.innerHTML='
ecshop实现ajax的tab切换效果
'; } Ajax.call('ajax.php?act='+act,'id='+id,setTabResponse,'get','json'); function setTabResponse(res) { //alert(res.content); target.innerHTML=res.content; } for(i=1;i<=n;i++){ var menu=document.getElementById(name+i); var con=document.getElementById("con_"+name+"_"+i); menu.className=i==cursel?"hover":""; con.style.display=i==cursel?"block":"none"; } }

php处理业务

$act = !empty($_GET['act']) ? $_GET['act'] : '';
if ($act == 'cat_rec')
{
    $rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot');
    $rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1';
    $cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0';
    include_once('includes/cls_json.php');
    $json = new JSON;
    $result   = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id);
    $children = get_children($cat_id);
    $smarty->assign($rec_array[$rec_type] . '_goods',      get_category_recommend_goods($rec_array[$rec_type], $children));    // 推荐商品
    $smarty->assign('cat_rec_sign', 1);
    $result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi');
    die($json->encode($result));
}
elseif($act=='get_tao_top')
{
    $json = new JSON;
    $result   = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id);
	$cat_id=intval($_REQUEST['id']);
	$taolist=get_tao_top($cat_id);
	$smarty->assign('top_tao_list',$taolist);
	$result['content']=$smarty->fetch('library/top_tao.lbi');
	
	die($json->encode($result));
}
正文完
 

公众号