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!.
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
Route::get('laravel-ajax-pagination',array('as'=>'ajax-pagination','uses'=>'[email protected]'));
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.
E-junkie: Sell digital downloads online
E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!
Also see:
public function studentList(Request $request){ $students = Product::paginate(5); if ($request->ajax()) { return view('presult', compact('students')); } return view('studentlist',compact('students')); }
Phase 3: Product Model
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Product extends Model { public $fillable = ['name','livedetails']; }
Phase 4: View studentlist.blade.php
<div class="row"> <div class="col-lg-12 margin-tb"> <div class="pull-left"> <h2>Simple Laravel AJAX Pagination with PHP and JQuery</h2> </div> </div> </div> <div id="product_container"> @include('presult') </div> $(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'); }); }
Phase 5: presult.blade.php
<table class="table table-bordered"> <tr> <th>Name</th> <th>Live Details</th> </tr> @foreach ($students as $student) <tr> <td>{{ $student->name }}</td> <td>{{ $student->livedetails }}</td> </tr> @endforeach </table> {!! $students->render() !!}
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.