【问题标题】:Laravel 5 pagination using ajaxLaravel 5 使用 ajax 进行分页
【发布时间】:2017-11-28 20:25:51
【问题描述】:

当我使用 laravel 分页时,我的页面会显示两次... 我的控制器是这样的......

controller.php

 public function index()
    {

        $restaurant = Restaurant::leftjoin('cities','restaurant.city','=','cities.id')
             ->leftjoin('cuisine','restaurant.cuisine','=','cuisine.id')
             ->select('*','restaurant.id as id','restaurant.created_at as user_created')
             ->paginate(3);

        $restaurant ->setPath('/elitecard/stores');
               return view('front_end.stores.stores',compact('restaurant'));
    }

blade.php

<div class="pagination-stores">
   {!! $restaurant->render() !!}
</div>
<div id="ajaxContent">
</div>

<script>
$('#ajaxContent').load('http://localhost/elitecard/stores');

$('.pagination a').on('click', function (event) {
    event.preventDefault();
    if ( $(this).attr('href') != '#' ) {
        $("html, body").animate({ scrollTop: 0 }, "fast");
        $('#ajaxContent').load($(this).attr('href'));
    }
});
</script>

【问题讨论】:

    标签: php jquery ajax pagination


    【解决方案1】:

    当您加载渲染链接的“href”时,它会返回完整视图。你有return view('front_end.stores.stores',compact('restaurant')); 试试这个:

    $('body').load($(this).attr('href'));
    

    除此之外:

    $('#ajaxContent').load($(this).attr('href'));
    

    【讨论】:

      猜你喜欢
      • 2015-01-01
      • 2015-09-24
      • 2019-02-15
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      相关资源
      最近更新 更多