Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

EcShop后台通过ajax搜索原理

ecshop教程:ecshop后台通过ajax搜索原理!ecshop的搜索其实是功能十分强大的,但是ecshop搜索功能前台和后台还不大一样。

ecshop教程:ecshop后台通过ajax搜索原理!ecshop的搜索其实是功能十分强大的,但是ecshop搜索功能前台和后台还不大一样。

前台主要是通过get方式,提交的url进行分页,而在ecshop的后台,则是接受表单的搜索条件,然后通过js发布到ajax.最后又通过ecshop的ajax将结果返回.然后在显示最后的搜索结果.

我们来举个例子,具体分析下ecshop后台通过ajax方式来进行搜索.

比如我们通过ecshop后台的ajax方式来搜索退换货订单

1、必须在htm中增增加以下搜索框,订单号

<input type="text" name="order_sn" size="15" />

2、html中的ajax可以写成以下格式

     listTable.filter['order_sn'] = Utils.trim(document.forms['searchForm'].elements['order_sn'].value);
     listTable.filter['page'] = 1;
     listTable.loadList();

我们可以看到以下,就是通过listTable.loadList();来触发ajax的。

3、我们再看php调用。

 $result = get_filter();
    if ($result === false)
    {
      如果返回结果为空,那么就进行ajax结果筛选
     $filter['invoice_no']   = empty($_REQUEST['invoice_no']) ? '' : trim($_REQUEST['invoice_no']);
        if ($_REQUEST['is_ajax'] == 1)
        {
            $filter['order_sn'] = json_str_iconv($filter['order_sn']);
        }
        $filter['sort_by']    = empty($_REQUEST['sort_by']) ? 'cid' : trim($_REQUEST['sort_by']);
        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
         $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('change') .
               " WHERE 1 " . $where;
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);
        $filter = page_and_size($filter);
        /* 获活动数据 */
        $sql = "SELECT * ".
               " FROM " . $GLOBALS['ecs']->table('change') .
               " WHERE 1 " . $where .
               " ORDER by $filter[sort_by] $filter[sort_order] LIMIT ". $filter['start'] .", " . $filter['page_size'];
        $filter['keywords'] = stripslashes($filter['keywords']);
        set_filter($filter, $sql);
      
   }else{
        $sql    = $result['sql'];
        $filter = $result['filter'];
}

4、最后将查询结果返回

$arr = array('res' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
    return $arr;

我们在来分析下,res是返回的所有数据,filter是过滤检索条件,page_count是分页数量,record_count表示查询的记录总数.通过以上封装,我们可以顺利的在ecshop后台使用ajax检索数据

温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
编程技巧

PbootCMS模板首页如何某个指定的栏目名称和链接

2022-8-4 9:00:00

编程技巧

PbootCMS模板修改模板保存目录设置二级子目录

2022-8-11 0:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索