Laravel 4.2 ajax 分页路由问题

Laravel 4.2 ajax pagination Routing Issue

在控制台中显示此消息

GET http://localhost/ajax/pagination?page=5 404 (Not Found)

查看页面(pages.post):

  @foreach ($posts as $post)

  <article>
      <h2>{{ $post->title }}</h2>

  </article>

@endforeach

 {{ $posts->links() }}

<script>
    $(document).ready(function() {
        $(document).on('click', '.pagination a', function (e) {
            getPosts($(this).attr('href').split('page=')[1]);
            e.preventDefault();
        });
    });

    function getPosts(page) {
        $.ajax({
            type:'GET',
            url : '/ajax/pagination?page=' + page,
        }).done(function (data) {
            $('.posts').html(data);
            location.hash = page;
        })
    }    
</script>

路线:

Route::get('/ajax/pagination',array('before' =>'auth' , 
           'uses'=>'CampaignsController@showPostspag'));

控制器:

public function showPostspag()
{
    $posts = Address::paginate(5);
    return View::make('pages.post')->with('posts',$posts);
}

我的错误在哪里?我认为这是 ajax url 和路由问题..

试试这个..

如果"ajax"您的根目录意味着更新以下代码

function getPosts(page) {
    $.ajax({
        type:'GET',
        url : 'pagination?page=' + page,
    }).done(function (data) {
        $('.posts').html(data);
        location.hash = page;
    })
}

路线:

Route::get('pagination',array('before' =>'auth' , 
    'uses'=>'CampaignsController@showPostspag'));