码迷,mamicode.com
首页 > Web开发 > 详细

laravel5.6中jquery+ajax分页

时间:2019-04-25 10:25:23      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:dev   each   rev   last   操作   obj   charset   pos   onclick   

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分页

标签:dev   each   rev   last   操作   obj   charset   pos   onclick   

原文地址:https://www.cnblogs.com/yingyong/p/10766666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!