ecshop商城红 将Ajax和Smarty fetch的结合方法
更新时间:2016-07-25 点击量:1615
Tag关键词: 商城 ecshop模板 ecshop4.0模板 二次开发 ecshop3.6模板 ecshop小程序
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
如果文章对您有帮助,就打赏一个吧