Monday, April 3, 2017

Blank page when going next page with jquery

I'm trying to use jquery to go to the next page of my comments using laravel's pagination. The problem I'm having is that I'm getting a blank page but in my firebug under "network" I do see my page 2 comments.

my comments.blade.php

@extends('templates::layouts.public')
@section('content')

<div class="row">
    <div class="col lg-12">
        <div class="comments endless-pagination" data-next-page="{!! $comments->nextPageUrl() !!}">
            @foreach($comments as $t)
                <h1>{!! $t['name'] !!}</h1>
                <p>{!! $t['comment'] !!}</p>
                <hr>
            @endforeach

            {!! $comments->render() !!}
        </div>
    </div>
</div>

@stop 

my OpenController

public function slug(Request $request, $slug){
    $stories = Story::where('slug', $slug)->get();

    $slug = $slug;

    $story = Story::where('slug', $slug)->first();
    $comments = $story->comment()->paginate(2);

    if($request->ajax())
    {
        return [
            'comments' => view('open::public.ajax.comments')->with(compact('comments'))->render(),
            'next_page' => $comments->nextPageUrl()
        ];
    }


    return view('open::public.single-story', compact('stories', 'slug', 'comments'));
}

my js

$(document).ready(function(){
    $('body').on('click', '.pagination a', function(e){

        e.preventDefault();
        var url = $(this).attr('href');

        $.get(url, function(data){
            $('.comments').html(data);
        });
    });
});



via Isis

Advertisement