Alfiza malek
Alfiza malek

Reputation: 1004

How to remove #symbol from Laravel pagination URL

In my Laravel project I was using the Laravel pagination, and calling it through ajax but now I want to add the sorting searching and something. so I want my URL like http://localhost:8000/test/sites?page=2&sort=name&order=asc but I am getting URL like http://localhost:8000/test/sites#?page=2 so how can I remove the # which is coming from Laravel code?

  $sites = DB::table('to_jobs')
  ->select(array(
      'to_jobs.rec_id',
      'to_jobs.contarct_code',
      'to_jobs.job_num',
      'to_sites.site_name',
      'to_sites.postcode',
      'to_sites.site_id' 
  ))
  ->leftjoin('to_sites', 'to_jobs.fk_site_id', '=', 'to_sites.site_id')
  /* ->join(DB::raw('(SELECT rec_id FROM   to_jobs LIMIT  299990, 10) AS t'), function($join) {
      $join->on('t.rec_id', '=', 'to_jobs.rec_id');
  })*/
  ->paginate(10);

  if (Request::ajax()) {    
      return Response::json(View('sites/site_data',compact('sites'),compact('user_data'))->render());
  }

Do I need to change in render()?

Upvotes: 0

Views: 671

Answers (2)

Yagnesh bhalala
Yagnesh bhalala

Reputation: 1315

You can just remove give line from your script.

`location.hash= '?page=' + page;`

Upvotes: 0

Alfiza malek
Alfiza malek

Reputation: 1004

$(document).ready(function() {
                            $(document).on('click', '.pagination a', function (e) {
                                getPagePosts($(this).attr('href').split('page=')[1]);
                                e.preventDefault();
                            });
                            $(document).on('click', '.sorting', function (e) {
                                getSortPosts($('.pagination .active span').html(),$(this).attr('aria-label'),$(this).attr('aria-sort'));
                                e.preventDefault();
                            });
                        });
                        function getPagePosts(page) {
                            $.ajax({
                                url : '?page=' + page ,
                                dataType: 'json',
                            }).done(function (data) {
                                $('.posts').html(data);
                                location.hash= '?page=' + page ;
                            }).fail(function () {
                                alert('Posts could not be loaded.');
                            });
                    }                        

Thanks i found it here at location.hash. But recently i know that if i remove the .hash .can you please explain why it refresh the pahe if hash not added and if added then not refresh the page

Upvotes: 0

Related Questions