无刷新点击实现加载更多数据
最后更新于:2022-04-01 23:50:35
> 无刷新点击实现加载更多数据
# html代码
~~~
~~~
# jquery代码
~~~
var cid = "";
i = 2; //当前页数
var domain = window.location.host; //域名
var url_dom = "http://"+domain+"/index.php?g=portal&m=list&a=more";
function lmore() {
$.getJSON(url_dom, {page: i,cid: cid}, function(json) {
if (json) {
var str = "";
$.each(json, function(index, array) {
var id = array['tid'];
var cid = array['term_id'];
var im = array['thumb'];
var url = window.location.pathname ; // 路径
var full = url+"?g=&m=article&a=index&id="+id+"&cid="+cid; //完整的详情路径
var str = "";
var str = str + "
';
" +"" + "" + " " + "" + "
";
$(".lists-img").append(str);
$(".case-bos").hover(
function(){
id=$(this).index();
$(".inner").eq(id).fadeIn(200);
},
function(){
$(".inner").eq(id).fadeOut(200);
}
);
});
} else {
showEmpty();
}
});
i++;
}
function showEmpty() {
$(".row-more").find("p").text("别滚动了,已经到底了... ...");
}
~~~
# php代码
~~~
public function more(){
$page = intval($_GET['page']); //获取请求的页数
$cid = intval($_GET['cid']); //分类id
$pagenum = 8; //每页数量
$start = ($page - 1) * $pagenum;
$tag = "order:post_date desc;limit:$start,$pagenum";
$result = sp_sql_posts_bycatid($cid,$tag);
foreach ($result as &$value) {
$value['smeta']=json_decode($value['smeta'], true);
$value['thumb']=$value['smeta']['thumb'];
$term_id=$value['term_id'];
$term=sp_get_term($term_id);
$value['claname']=$term['name'];
}
if ($result) {
echo json_encode($result,true); //转换为json数据输出
}
}
~~~
" + "查看案例" + "