加参数前,程序正常运行:
原来lib_insert.php的插入历史函数没有加入参数,
function insert_history()//lib_insert.php
{
    $str = '';
    if (!empty($_COOKIE['ECS']['history']))
    {
        $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
        $sql   = 'SELECT goods_id, goods_name, goods_thumb, shop_price FROM ' . $GLOBALS['ecs']->table('goods') .
                " WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
        $query = $GLOBALS['db']->query($sql);
        $res = array();
        while ($row = $GLOBALS['db']->fetch_array($query))
        {
            $goods['goods_id'] = $row['goods_id'];
            $goods['goods_name'] = $row['goods_name'];
            $goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
            $goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
            $goods['shop_price'] = price_format($row['shop_price']);
            $goods['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
            $str.='<ul class="clearfix"><li class="goodsimg"><a href="'.$goods['url'].'" target="_blank"><img src="'.$goods['goods_thumb'].'" alt="'.$goods['goods_name'].'" class="B_blue" /></a></li><li><a href="'.$goods['url'].'" target="_blank" title="'.$goods['goods_name'].'">'.$goods['short_name'].'</a><br />'.$GLOBALS['_LANG']['shop_price'].'<font class="f1">'.$goods['shop_price'].'</font><br /></li></ul>';
        }
        $str .= '<ul id="clear_history"><a onclick="clear_history()">' . $GLOBALS['_LANG']['clear_history'] . '</a></ul>';
    }
    return $str;
}
在common.js中的addToCart函数可以通过ajax.call到flow.php
function addToCart(goodsId, parentId)
{
  var goods        = new Object();
  var spec_arr     = new Array();
  var fittings_arr = new Array();
  var number       = 1;
  var formBuy      = document.forms['ECS_FORMBUY'];  // 检查是否有商品规格 
  if (formBuy)
  {
    spec_arr = getSelectedAttributes(formBuy);    if (formBuy.elements['number'])
    {
      number = formBuy.elements['number'].value;
    }
  }  goods.spec     = spec_arr;
  goods.goods_id = goodsId;
  goods.number   = number;
  goods.parent   = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);  Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
}但是在lib_insert.php中加入参数之后
function insert_history($arr)
{
    $str = '';
    if (!empty($_COOKIE['ECS']['history']))
    {
        $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
        $sql   = 'SELECT goods_id, goods_name, goods_thumb, shop_price FROM ' . $GLOBALS['ecs']->table('goods') .
                " WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
        $query = $GLOBALS['db']->query($sql);
$res = array();
        while ($row = $GLOBALS['db']->fetch_array($query))
        {
//print_r ($GLOBALS['db']->fetch_array($query));
            $goods['goods_id'] = $row['goods_id'];
            $goods['goods_name'] = $row['goods_name'];
            $goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
            $goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
            $goods['shop_price'] = price_format($row['shop_price']);
            $goods['url'] = build_uri('goods', array('gid'=>$row['goods_id'], 'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']), $row['goods_name']);//'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']是新加入的参数
            $str.='<ul class="clearfix"><li class="goodsimg"><a href="'.$goods['url'].'" target="_blank"><img src="'.$goods['goods_thumb'].'" alt="'.$goods['goods_name'].'" class="B_blue" /></a></li><li><a href="'.$goods['url'].'" target="_blank" title="'.$goods['goods_name'].'">'.$goods['short_name'].'</a><br />'.$GLOBALS['_LANG']['shop_price'].'<font class="f1">'.$goods['shop_price'].'</font><br /></li></ul>';
        }
        $str .= '<ul id="clear_history"><a onclick="clear_history()">' . $GLOBALS['_LANG']['clear_history'] . '</a></ul>';
    }
    return $str;
}
加入的参数是$arr,从模版中获得的参数是'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc'],加了参数以后,出现问题:
---------------------------------------------------------------------------
在加入参数之后,addToCart在Ajax.call后无法跳转的flow.php
错误在:
case "JSON" :
        result = this.preFilter(xhr.responseText);
        try
        {
          result = result.parseJSON();
        }
        catch (ex)
        {
          throw this.filename + "/parseResult() error: can't parse to JSON.\n\n" + xhr.responseText;//程序运行到这里无法继续运行
        }
        break;
在insert_history中不加参数addToCart就可以跳转到flow.php,但是加入参数之后就无法跳转到flow.php

解决方案 »

  1.   

    参数中是否有中文,如果是 urlencode 传过去看看
      

  2.   

    function insert_history($arr) 

        $str = ''; 
        if (!empty($_COOKIE['ECS']['history'])) 
        { 
            $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id'); 
            $sql  = 'SELECT goods_id, goods_name, goods_thumb, shop_price FROM ' . $GLOBALS['ecs']->table('goods') . 
                    " WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0"; 
            $query = $GLOBALS['db']->query($sql); 
    $res = array(); 
            while ($row = $GLOBALS['db']->fetch_array($query)) 
    问题出在这里,原因自己分析。
            { 
    //print_r ($GLOBALS['db']->fetch_array($query)); 
                $goods['goods_id'] = $row['goods_id']; 
                $goods['goods_name'] = $row['goods_name']; 
                $goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; 
                $goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); 
                $goods['shop_price'] = price_format($row['shop_price']); 
                $goods['url'] = build_uri('goods', array('gid'=>$row['goods_id'], 'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']), $row['goods_name']);//'aaa'=>$arr['aaa'], 'bbb'=>$arr['bbb'], 'ccc'=>$arr['ccc']是新加入的参数 
                $str.=' <ul class="clearfix"> <li class="goodsimg"> <a href="'.$goods['url'].'" target="_blank"> <img src="'.$goods['goods_thumb'].'" alt="'.$goods['goods_name'].'" class="B_blue" /> </a> </li> <li> <a href="'.$goods['url'].'" target="_blank" title="'.$goods['goods_name'].'">'.$goods['short_name'].' </a> <br />'.$GLOBALS['_LANG']['shop_price'].' <font class="f1">'.$goods['shop_price'].' </font> <br /> </li> </ul>'; 
            } 
            $str .= ' <ul id="clear_history"> <a onclick="clear_history()">' . $GLOBALS['_LANG']['clear_history'] . ' </a> </ul>'; 
        } 
        return $str;