简体   繁体   中英

maintain ajax pagination upon clicking back button in Laravel 5.3 application

I'am making use of laravel pagination($data->links()) for ajax pagination using below code.

$(document).on("click", '.pagination a', function(e) {
    e.preventDefault();
    var url = $(this).attr('href');
    loadArts(url);
});

function loadArts(url) {
    $.ajax({
        url : url
    }).done(function (data) {
        $(".image-masonry").html(data);

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

it's working fine, but upon clicking back button from an inner page, browser returning back to page1. Here is the controller function

public function index(Request $request)
{
    $arts = Art::with('artist')->orderBy('id','ASC')->paginate(10);
    if($request->ajax()){            
        return view('art::art.list', compact('arts');
    }
    return view('art::art.index', compact('arts');
}

.image-masonary is the class in index.blade.php to which contents of list.blade.php is being loaded upon pagination.

This is the url : http://localhost:8000/admin/arts

I tried this method , history.pushState({ path: url }, '', url);

then back button is taking ajax route, but getting only broken view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM