ecshop Ajax和Smarty fetch的结合
发布时间:12/03 来源: 浏览:
关键词:
ecshop的ajax无刷新异步获取数据技术十分流行,但是我之前的做法是获取一堆json的数值.然后在前端页面由javascript来解析替换html.这样操作比较繁琐。
在开发ecshop的过程中,发现ecshop的无刷新加载,对于返回来的json值没有作解析。而是直接用innerHTML替换
/admin/js/listtable.js
document.getElementById('listDiv').innerHTML = result.content;
这是由于在服务端,即php文件里已经把数据组合成可以直接显示的html了。
这个是用smarty->fetch函数实现。fetch函数和display不同之处,fetch只赋值,不显示。
$order_list = order_list(); $smarty->assign('order_list', $order_list['orders']); $smarty->assign('filter', $order_list['filter']); $smarty->assign('record_count', $order_list['record_count']); $smarty->assign('page_count', $order_list['page_count']); $sort_flag = sort_flag($order_list['filter']); $smarty->assign($sort_flag['tag'], $sort_flag['img']); make_json_result($smarty->fetch('order_list.htm'), '', array('filter' => $order_list['filter'], 'page_count' => $order_list['page_count']));
这样ajax前端获取的result.content就是一组html内容了。不用再用js操作替换html