0
votes

Showing this message in console

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

View page (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 :

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

Controller :

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

Where is my mistake? I think that is ajax url and routing problem..

1
what error you have? - Deenadhayalan Manoharan
what is root name? it is ajax? - Deenadhayalan Manoharan
@Jocker Error is GET localhost/ajax/pagination?page=5 404 (Not Found) - Inspire Shahin
what a result or return value when you manually go to localhost/ajax/pagination?page=5 ? - Mohd Dhiyaulhaq
I followed other lesson for make L4.2 ajax pagination, I show that this code worked perfectly, but it not works for me! - Inspire Shahin

1 Answers

0
votes

Try this..

if "ajax" your root directory means update following code

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

Route :

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