laravel5.6中jquery+ajax分页
Posted yingyong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel5.6中jquery+ajax分页相关的知识,希望对你有一定的参考价值。
public function shows(Request $request){ $p=$request->get("page"); $page=empty($p)?1:$p; $count=DB::table("shop")->count(); $length = 4; $num_page = ceil($count/$length); $limit = ($page-1)*$length; $data=DB::select("select * from shop limit $limit,$length"); $arr[‘data‘]=$data; $arr[‘home_page‘] = 1; $arr[‘prev_page‘] = $page-1<=1?1:$page-1; $arr[‘next_page‘] = $page+1>=$num_page?$num_page:$page+1; $arr[‘last_page‘] = $num_page; return view("/index/month/shows",[‘list‘=>$arr]); }
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <center> <form action="/index/month/search" method="post"> <input type="text" name="goods"> <input type="submit" value="搜索"> </form> <table border="3"> <tr> <td>ID</td> <td>商品</td> <td>积分</td> <td>操作</td> </tr> <?php foreach ($list[‘data‘] as $key=>$v) {?> <tr> <td><?php echo $v->id ?></td> <td><?php echo $v->goods ?></td> <td><?php echo $v->socre ?></td> <td><a href="/index/month/buy?goods=<?php echo $v->goods ?>&socre=<?php echo $v->socre ?>"><button>点击购买</button></a></td> </tr> <?php }?> </table> <a href="javascript:void(0);" onclick="page({{$list[‘home_page‘]}})">首页</a> <a href="javascript:void(0);" onclick="page({{$list[‘prev_page‘]}})">上一页</a> <a href="javascript:void(0);" onclick="page({{$list[‘next_page‘]}})">下一页</a> <a href="javascript:void(0);" onclick="page({{$list[‘last_page‘]}})">尾页</a> </center> </body> </html> <script src="/js/jquery.js"></script> <script> function page(obj){ $.get("/index/month/shows?page="+obj, function(data){ $("body").html(data); } ); } </script>
以上是关于laravel5.6中jquery+ajax分页的主要内容,如果未能解决你的问题,请参考以下文章
使用 JQUERY 和 AJAX 在 Laravel 分页中重新填充表数据