alauddinjahin's avatar

Need Help for Ajax pagination with Laravel 6

Dear friends, I have got a problem for making pagination in laravel 6 .My problem is that when I am trying to make pagination for my e-commerce project on shop page . I can't fetch my category and sub category id on url for making query as well what I need.Tell me how can I fetch my category and sub category id on url with ajax. Thanks ...............

0 likes
3 replies
jlrdw's avatar

There was a good post a while back on this, sorry I did not save that link.

But if you punch in to Google this.

site:laracasts.com Ajax pagination

You will see several good past discussions.

Explanation, Google search is more powerful than the site search here.

alauddinjahin's avatar

May be you don't understand my requirement .I have worked before with ajax but that was so simple .Just pagination with ajax but right now I need ajax pagination in my Laravel project with category and sub category .Tell me once more please ...so I can do that as well. How can I fetch category and sub category id on url through ajax request. Here is my route ..

Route for shop page : Route::get('/shop/{category}/{subCategory?}', 'FrontendController@productCategory')->name('frontend.shop');

Route For Ajax Request: Route::get('/shop-paginate', 'FrontendController@shopPaginate')->name('shop_paginate');

Ajax Code : $(document).ready(function(){

    $(document).on('click','.pagination a', function(event){
        event.preventDefault();
        var myUrl = $(this).attr('href');
        var page = $(this).attr('href').split('page=')[1];
        
        $('li').removeClass('active');
           $(this).parent('li').addClass('active');
        shopPaginate(page);
    }); 

function shopPaginate(page){
      $.ajax({
        type:"get",
        url: "{!! route('shop_paginate')!!}?page="+page,
        cache: false,
        success:function(data){
          $('#rangediv').html(data);
           location.hash = page;
         }
      });
}

});

jlrdw's avatar

category and sub category

A div for category with next button

A div for sub category with next button

In other words setup double pagination.

just quick example and easy to do. Of course style as you desire.

Please or to participate in this conversation.