vendredi 24 février 2017

Multiple pagination with ajax in laravel

I have this problem with multiple pagination on one page in laravel 5.0 for almost a week.Now I tried ajax hoping that i can do it first in one pagination but the function is failing.Since i'm not get use of using ajax, i don't know what is lucking on my script.Hoping someone could help me configuring it out.

view.blade.php

@extends('layouts.master')
@section('content')
<br>
<div class="container">

<div class="paginate a">
    @if(count($scholars) > 0)

    @foreach($scholars as $scholar)

      <div class = "col-md-6">
        <div class = "panel">
          <div class = "row">
            <div class="col-sm-12">
              <div class = "thumbnail"><br>
                <img src = "/" alt = "Generic placeholder thumbnail">
              </div>
              <div class = "caption">
                <div class="col-sm-12">
                  <div class="col-sm-12">
                    <div class="col-sm-12">   
                      <h3>Name: {!! $scholar->scholar_lname !!}, {!! $scholar->scholar_fname !!}</h3><br>
                      <p> 
                        <a href = "/View-Scholar-Information/{!! $scholar->scholar_id !!}" class = "btn btn-default btn-info">View More Details</a>
                        <a href = "/Update-Scholar-Information/{!! $scholar->scholar_id !!}" class = "btn btn-default btn-info"><b class="fa fa-edit"> Update</b></a>
                        <a href = "/View-Scholar-Feedback" class = "btn btn-default btn-info"><i class="fa fa-comment"> View Feedback</i></a>
                        <a href = "/View-Scholar-Feedback" class = "btn btn-default btn-info"><i class="fa fa-list"> List Of Sponsor</i></a>
                        <a href = "#" class = "btn btn-default btn-info"><b class="fa fa-close"></b></a>
                      </p><br>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

    @endforeach
    @endif
    {!! $scholars->render() !!}

</div><!--end of class="paginate a"  -->

<br>
<div class="row">

  <div id="paginate b">
    @if(count($scholars_all) > 0)
    @foreach($scholars_all as $s)
        <div class = "col-md-6">
          <div class = "panel">
            <div class = "row">
              <div class="col-sm-12">
                <div class = "thumbnail"><br>
                  <img src = "/" alt = "Generic placeholder thumbnail">
                </div>
                <div class = "caption">
                  <div class="col-sm-12">
                    <div class="col-sm-12">
                      <div class="col-sm-12">   
                        <h3>Name: {!! $s->scholar_lname !!}, {!! $s->scholar_fname !!}</h3><br>
                        <p> 
                          <a href = "/View-Scholar-Information/{!! $scholar->scholar_id !!}" class = "btn btn-default btn-info">View More Details</a>
                          <a href = "/Update-Scholar-Information/{!! $scholar->scholar_id !!}" class = "btn btn-default btn-info"><b class="fa fa-edit"> Update</b></a>
                          <a href = "/View-Scholar-Feedback" class = "btn btn-default btn-info"><i class="fa fa-comment"> View Feedback</i></a>
                          <a href = "/View-Scholar-Feedback" class = "btn btn-default btn-info"><i class="fa fa-list"> List Of Sponsor</i></a>
                          <a href = "#" class = "btn btn-default btn-info"><b class="fa fa-close"></b></a>
                        </p><br>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
    @endforeach
    @endif
    {!! $scholars_all->render() !!}
    </div>

</div>
<script src="http://ift.tt/16ygW8q"></script>


   <script>

    $(window).on('hashchange',function(){
      page = window.location.hash.replace('#','');
      getPosts(page);
    });

     $(document).on('click','.pagination a', function(e){
      e.preventDefault();
      var page = $(this).attr('href').split('page=')[1];

       getPosts(page);
      location.hash = page;
    });

        function getPosts(page) {
          //console.log('show page = '+ page);

            $.ajax({
                //type : "Get",
                url : 'List-Of-Ngo-Scholar?page=' + page,//route
                dataType: 'json',
                success:function(data){
                  alert('ok');
                }

            }).done(function (data) {

              //console.log(data);
             // location.hash = page;
                $('.paginate a').html(data);

            }).fail(function () {
                alert('Posts could not be loaded.');
            });


        }
    </script>
@stop

//controller

public function ListScholar()
    {
    $id = Auth::User()->id;
    $scholars = Scholar::where('ngo_id', '=', $id)->paginate(1);
    $scholars_all = Scholar::select('*')->paginate(2);


        if (Request::ajax()) {
            dd('get in');
            return Response::json(View::make('List-Of-Ngo-Scholar', array('scholars' => $scholars))->render());
        }


        //$allusers = User::where('id','>',0)->paginate(2,['*'], 'allusers');

        return View::make('pages.Ngo.List-Of-Ngo-Scholar',compact('scholars','scholars_all'));
    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lOjKJt
via IFTTT

Aucun commentaire:

Enregistrer un commentaire