2016-01-06 135 views
1

當我使用laravel分頁顯示我的網頁兩次...... 我的控制器是這樣的......Laravel 5分頁使用AJAX

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

當您載入渲染鏈接的'href'時,它會返回完整視圖。你有return view('front_end.stores.stores',compact('restaurant')); 試試這個:這

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

INSEAD:

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