0

I want to use infinite ajax scroll pagination for my blog, but unfortunately I do not have a result!? I still get this error message : server not responding... Below the code used.

controller:

$posts =Post::paginate(5);
if ($request->ajax()) {
    $view = view('user.list.data', compact('posts'))->render();
    return response()->json(['html'=>$view]);
}
return view('user.list.page', compact('posts');

view:

<div class="container">
    <h2 class="text-center">Liste poste</h2>
    <br/>
    <div class="col-md-12" id="post-data">
        @include('user.list.data')
    </div>
</div>
<div class="ajax-load text-center" style="display:none">
    <i class="fa fa-spinner fa-spin" style="color: #dd4b39; font-size:36px"></i>
</div>

<script type="text/javascript">
    var page = 1;

    $(window).scroll(function() {
        if($(window).scrollTop() + $(window).height() >= $(document).height()) {
            page++;
            loadMoreData(page);
        }
    });

    function loadMoreData(page) {
        $.ajax({
            url: '?page=' + page,
            type: "get",
            beforeSend: function() {
                $('.ajax-load').show();
            }
        }).done(function(data) {
            if(data.html == " ") {
                $('.ajax-load').html("No more records found");
                return;
            }
            $('.ajax-load').hide();
            $("#post-data").append(data.html);
        }).fail(function(jqXHR, ajaxOptions, thrownError) {
            alert('server not responding...');
        });
    }
</script>

view data:

@foreach($posts as $post)
<div>
    <h3>
        <a href="">{{ $post->title }}</a>
    </h3>
    <p>{{ $post->description }}</p>

    <div class="text-right">
        <button class="btn btn-success">Read More</button>
    </div>
    <hr style="margin-top:5px;">
</div>
@endforeach
Alexandre
  • 474
  • 2
  • 14
visulo
  • 373
  • 2
  • 9
  • 23
  • is `return view('user.list.page', compact('posts');` not `return view('user.list.page', compact('posts'));` instead? (closing parenthesis) – Alexandre Dec 08 '16 at 08:45
  • are you sure `url` variable in `ajax` object is correct? did you tried defining this variable with an example such as `index.php?blog` or something strict? (which you are sure it exist) – Alexandre Dec 08 '16 at 08:48
  • It is a typing error on my part, but it is always not running! – visulo Dec 08 '16 at 08:52
  • Even when I set the variable as : url: '12/journal?page=' + page, I get the same error! – visulo Dec 08 '16 at 09:05
  • When I check the Console output, I see the link on the following pages but I am not receiving nothing in the browser! – visulo Dec 08 '16 at 09:16
  • 1
    could you please open the "Network" tab, and get more information about the loaded page (with AJAX)? – Alexandre Dec 08 '16 at 09:18
  • you may want to look here in order to do so: http://stackoverflow.com/a/3019085/5276272 ; then you will be able to add some bebugging within the Controller piece of code and watch its result within the "Network" XHR entry (Response sub-tab) on Google Chrome – Alexandre Dec 08 '16 at 09:23
  • 1
    I get this error message : NotFoundHttpException in RouteCollection.php in Network" XHR – visulo Dec 08 '16 at 09:39
  • so in my point of view it seams the request has no controller which is able to handle the AJAX request – Alexandre Dec 08 '16 at 09:57
  • I fixed the error, there was other variable I not add in the ajax requet such as: $view = view('user.pro.data',compact('recents', 'follows', 'profi', 'email',..... Currently I do not get an error but I get nothing in the browser! – visulo Dec 08 '16 at 10:05
  • does my comments were usefull in order to find this? In the preview, still in the XHR subtab, what do you get? Still the NotFoundHttpException or something like HTML or your data? Depending on that, you may have to debug the Controller, or to fix how the jQuery function handle results... :) – Alexandre Dec 08 '16 at 10:08
  • Exactly your comment on the network XHR help me to find the error, thank you once again :) – visulo Dec 08 '16 at 10:37
  • how to exclude footer hight ?? – Jagdish Chaudhary Apr 04 '17 at 11:04

0 Answers0