JQ ajax代码:
<script type="text/javascript"> //格式化时间戳 function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '); } var page = 3; $(function() { $('#morse').on('click', function() { page += 3; $.ajax({ url:"__URL__/index", data:{ p:page, }, type:"post", success:function(data){ var html = ''; for(var i in data){ var addtime = getLocalTime(data[i].addtime); html += '<div class=\"am-container\" id=\"morelist\">'; html +='<ul id=\"list\" class=\"am-list\">'; html +='<li class=\"am-g am-list-item-desced am-padding-horizontal-sm\">'; html +='<a class=\"am-list-item-hd\" target=\"_blank\" href=\"\">'+data[i].title+'</a>'; html +='<div class=\"am-list-item-text\">发布时间:'+addtime+'</div>'; html +='<div class=\"am-list-item-text\">'; html +='总阅读量:<span class=\"am-text-danger\">'+data[i].readcount+'</span> '; html +='</li>'; html +='</ul>'; html +='</div>'; } $("#list").append(html);//在后面追加显示 } }); }); });</script>
public function index(){ if(!empty($_POST['p'])){//点击加载更多 $p = $_POST['p'];//3 6 9 $amount = 3; //显示条数 //$count = M("micro_article")->count();//总数 $Model = new \Think\Model(); $list = $Model->query("SELECT * FROM `day_micro_article` ORDER BY addtime DESC LIMIT $p,$amount"); $this->ajaxReturn($list); } $count = M("micro_article")->count(); $Page = new \Think\Page($count, 3); $show = $Page->show(); $Model = new \Think\Model(); //默认显示最新三条 $list = $Model->query("SELECT * FROM `day_micro_article` WHERE `status` = 1 AND `is_rec` = 1 ORDER BY `addtime` DESC LIMIT " . $Page->firstRow . ',' . $Page->listRows); $shouyi= M("Micro_customlucre")->where(array("zid"=>1))->find(); $this->assign('list', $list); $this->assign('vo1', $shouyi); $this->assign('show', $show); $this->display(); }
function getLocalTime(nS) { var d = new Date(parseInt(nS) * 1000); return d.getYear() + '/' + (d.getMonth()+1) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();}
你返回的数据是txt,不是json。所以解释不出。
<script type="text/javascript"> //格式化时间戳 function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '); } var page = 3; $(function() { $('#morse').on('click', function() { page += 3; $.ajax({ url:"__URL__/index", data:{ p:page, }, type:"post", dataType:"JSON", success:function(data){ var html = ''; for(var i in data){ var addtime = getLocalTime(data[i].addtime); html += '<div class=\"am-container\" id=\"morelist\">'; html +='<ul id=\"list\" class=\"am-list\">'; html +='<li class=\"am-g am-list-item-desced am-padding-horizontal-sm\">'; html +='<a class=\"am-list-item-hd\" target=\"_blank\" href=\"\">'+data[i].title+'</a>'; html +='<div class=\"am-list-item-text\">发布时间:'+addtime+'</div>'; html +='<div class=\"am-list-item-text\">'; html +='总阅读量:<span class=\"am-text-danger\">'+data[i].readcount+'</span> '; html +='</li>'; html +='</ul>'; html +='</div>'; } $("#list").append(html);//在后面追加显示 } }); }); });</script>
function getLocalTime(nS) { var d = new Date(parseInt(nS) * 1000); return d.getYear() + '/' + (d.getMonth()+1) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();}
function getLocalTime(nS) { var d = new Date(parseInt(nS) * 1000); return d.getYear() + '/' + (d.getMonth()+1) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();}