Paginate Laravel 5.2 with Jquery
<p>I know how to paginate in Laravel, I tried it according to its docs and its so easy.However, I am implementing a Jquery autocomplete on its one of its view, and pagination this time does not work. How would you achieve this?</p>

<p>jquery</p>

<pre><code>  $("#city_autocomplete").autocomplete({
        source: '/lead-users/autocomplete',
        minLength: 2,
        select: function(event, ui) {
            $("#city_autocomplete").val(ui.item.value);
        }
    });
</code></pre>

<p>Controller</p>

<pre><code> $leads = LeadUser::where('gender', 'LIKE', '%'.$gender.'%')
            -&gt;orderBy('first_name', 'ASC')
            -&gt;paginate(20);
</code></pre>

<p>View </p>

<pre><code>&lt;tbody&gt;
            @foreach($leads as $count)
            &lt;tr&gt;
                &lt;td&gt;{{ $count-&gt;getFullName() }}&lt;/td&gt;
                &lt;td&gt;{{ $count-&gt;email }}&lt;/td&gt;
                &lt;td&gt;{{ $count-&gt;city }}&lt;/td&gt;
                &lt;td&gt;{{ $count-&gt;state }}&lt;/td&gt;
                &lt;td&gt;{{ $count-&gt;getGender() }}&lt;/td&gt;
                &lt;td&gt;{{ $count-&gt;yesOrNo() }}&lt;/td&gt;
            &lt;/tr&gt;
            @endforeach
        &lt;/tbody&gt;
    &lt;/table&gt;
    {{ $counts-&gt;links() }}
</code></pre>

<p>Ok I update my Jquery</p>

<pre><code>&lt;script&gt;
    $(document).ready(function (){
        $("#city_autocomplete").autocomplete({
        source: '/lead-users/autocomplete',
        minLength: 2,
        select: function(event, ui) {
            $("#city_autocomplete").val(ui.item.value);
        }
    });
        $(window).on('hashchange',function(){
            page = window.location.hash.replace('#','');
            getItems(page);
        });
        $(document).on('click','.pagination a', function(e){
            e.preventDefault();
            var page = $(this).attr('href').split('page=')[1];
            // getItems(page);
            location.hash = page;
        });
        function getItems(page){
            $.ajax({
                url: '/lead-users/autocomplete?page=' + page
            }).done(function(data){
                $('#leads').html(data);
            });
        };
    });
&lt;/script&gt;
</code></pre>

<p>This will only work for the pagination 2(1,2,3,4,5,6) the rest will not redirect.It does change the url in the browser but nothing happens on the view</p>

<pre><code>city=Fremont#2
city=Fremont#3
city=Fremont#4
</code></pre>