当我使用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>
答案 0 :(得分:0)
当您加载渲染链接的'href'时,它会返回完整视图。你有return view('front_end.stores.stores',compact('restaurant'));
试试这个:
$('body').load($(this).attr('href'));
这一点:
$('#ajaxContent').load($(this).attr('href'));