php部分
public function lists(){
$post0 = input('get.');
$typeid = $post0['id'];
$arc_where = [
'typeid' => $typeid,
];
$archives = M('archives')->where($arc_where)->select();
$data = $archives;
$datas=[];
foreach($data as $k=>$v){
$datas['arcurl'] = diy_get_arcurl($v['aid'],$v['typeid']);
$datas['title'] = $v['title'];
$datas['litpic'] = $v['litpic'];
$datas['aid'] = $v['aid'];
$datass[$k] = $datas;
}
if($datass){
echo json_encode(['code'=>200,'data'=>$datass,'msg'=>'success'],JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}else{
echo json_encode(['code'=>'-1','msg'=>'error'],JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}
}
js部分:
!!id && $.ajax({
url: '/index.php/api/Product/lists/id/'+id,
type: 'GET',
dataType: 'json',
success: function (data) {
if(data.code==200){
console.log(data.data);
var dataList = data.data,html = '';
$.each(dataList, function(index,item){
html += '<div class="recommend-product-grid"><a href="'+dataList[index].arcurl+'" target="_blank"><div class="grid-box"><div class="grid-bg"></div><div class="grid-body"><img src="'+dataList[index].litpic+'"></div><div class="grid-name">'+dataList[index].title+'</div></div></a></div>'
})
$('#pd_recommend').html('').append(html);
setTimeout(function(){
!!scroller && scroller.update();
},500)
}else{
$("#pd_recommend").children().remove();
}
},
});