ecshop的搜索其实是功能十分强大的,但是ecshop搜索功能前台和后台还不大一样,然后通过js发布到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的。
$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检索数据
原文链接:https://www.f2er.com/ajax/162639.html