Ajax Pagination Issue

Published 2 years ago by Khudadad

I want to make the default laravel pagination do not refresh the page and following

http://sharpten.com/blog/2014/10/02/ajax-based-pagination-laravel-4.html tutorial but not working. getting 500 Internal error in Chrome console

    ( GET http://localhost:8000/stock?page=2 500 (Internal Server Error))

Any help.

tomopongrac

@Khudadad

Maybe you have some typo error in you code

Khudadad

This is the code:

function ajaxPagination(active){

 if(active===true){

        $('.pagination a').each(function(e){

            $( ".ajax_overlay" ).show();
            $( ".loader" ).show();

            $(this).attr('data',$(this).attr('href'));
            $(this).attr('href','javascript:void(0);');

            $(this).bind('click',function(){

                $.ajax({
                    url: $(this).attr('data')
                    })
                    .done(function( html ) {
                    $( ".ajaxable" ).html( '' );
                    $( ".ajaxable" ).html( html );

                    $( ".ajax_overlay" ).hide();
                    $( ".loader" ).hide();

                    });

            });

            });

     }

}

ajaxPagination(true);

Controller

  public function index()
    {

    $items = DB::table('items')
        ->join('categories','categories.cat_id','=','items.category_id')
        ->join('units','units.unit_id','=','items.unit_id')
        ->select('items.*','categories.cat_id','categories.category_name','units.unit_id','units.unit_name')
        ->where('items.quantity','>',0)
        ->paginate(1);
    $total = Item::where('status', 0)->count();
    if (Request::ajax()) {
        return Response::json((view('partials.pagination')->with(compact('items','total'))->render());
    }
    return view('stock.stock-list', compact('items','category', 'purchase_type', 'units','brands','total','menu', 'sub_menu'));
}
bestmomo
bestmomo
2 years ago (349,260 XP)

One more opening parenthesis '(' on this line :

return Response::json(view('partials.pagination')->with(compact('items','total'))->render());
Khudadad

Still same error

bestmomo
bestmomo
2 years ago (349,260 XP)

What is the text of the error ?

Khudadad

The error in the console:

 GET http://localhost:8000/stock?page=2 500 (Internal Server Error)

Please sign in or create an account to participate in this conversation.