Laravel JQuery AJAX Pagination Step By step

Rate this post

Laravel JQuery AJAX Pagination Step By step

In this Post We Will Explain About is Laravel JQuery AJAX Pagination Step By step With Example and Demo.

Welcome on infinityknow.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Laravel AJAX Pagination with JQuery

In this post we will show you Best way to implement How to Create an Ajax Pagination Using Laravel, hear for How to Laravel 5 AJAX Pagination using JQuery Example with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  Vue JS Dynamic component and template loading

Laravel Jquery Ajax Pagination Example From Scratch

here Example of the simple Laravel AJAX Pagination with JQuery following the list of Phase to learn step by step Laravel pagination using database with ajax jQuery.

Phase 1: Add Route

[php]
Route::get(‘laravel-ajax-pagination’,array(‘as’=>’ajax-pagination’,’uses’=>’[email protected]’));
[/php]

Phase 2: FileController

In this Phase no 2, we are simple creating a methods for student listing/displaying and check if there all the data will be ajax request then or as well as pass data without any templates.

[php]
public function studentList(Request $request){
$students = Product::paginate(5);
if ($request->ajax()) {
return view(‘presult’, compact(‘students’));
}
return view(‘studentlist’,compact(‘students’));
}
[/php]

Phase 3: Product Model

[php]
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
public $fillable = ['name','livedetails'];

READ :  Simple Vue datepicker Example

}
[/php]

Phase 4: View studentlist.blade.php

[php]

Simple Laravel AJAX Pagination with PHP and JQuery

@include(‘presult’)

$(window).on(‘hashchange’, function() {
if (window.location.hash) {
var livepage = window.location.hash.replace(‘#’, ”);
if (livepage == Number.NaN || livepage <= 0) {
return false;
}else{
getData(livepage);
}
}
});
$(document).ready(function()
{
$(document).on('click', '.pagination a',function(event)
{
$('li').removeClass('active');
$(this).parent('li').addClass('active');
event.preventDefault();
var myurl = $(this).attr('href');
var livepage=$(this).attr('href').split('livepage=')[1];
getData(livepage);
});
});
function getData(livepage){
$.ajax(
{
url: '?livepage=' + livepage,
type: "get",
datatype: "html",
})
.done(function(data)
{
console.log(data);

$("#product_container").empty().html(data);
location.hash = livepage;
})
.fail(function(jqXHR, ajaxOptions, thrownError)
{
alert('No any data or response from server');
});
}

[/php]

Phase 5: presult.blade.php

[php]

@foreach ($students as $student)

@endforeach

Name Live Details
{{ $student->name }} {{ $student->livedetails }}

{!! $students->render() !!}
[/php]

Example

I hope you have Got Laravel 5 AJAX Pagination with JQuery Example And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

Leave a Reply

Your email address will not be published.