0

I am fetching records via ajax with search parameters and want to have pagination also. It works fine if I use it with the same function which loads view, for example

  function viewOrder(Request $request){
   $data = products::where('categoryId', 1)->paginate(1);

    if ($request->ajax()){
      return view('store.showAjax')->with('data',$data);
    }
      return view('store.show')->with('data',$data);
  }

But my need is like this

  function viewOrder(){
      return view('store.show');
  }

  function searchOrder(Request $request){
      $data = products::where('categoryId', 1)->paginate(1);
      return view('store.show')->with('data',$data);
  }

In this way It creates pagination but when I click on page link it load store.show view twice in the same html page. How can I achieve correct pagination this way? Doing everything in viewOrder() function looks messy.

Mohsin
  • 179
  • 4
  • 13

1 Answers1

0

I just find out how to do it, simply passing full url instead passing ?page=1 in javascript function `

 function getData(url, page){
    $.ajax({
        url: url, //'?page=1',
        type: "get",
        datatype: "html",
        success: function(data){
          $("#tag_container").empty().html(data);
          location.hash = page;
        }
    });
}`
Mohsin
  • 179
  • 4
  • 13