How to implement AJAX on multiple laravel pagination
I have 2 LARAVEL paginations on one page, know i want to implement AJAX technology in order to achive paginations without reload of entire page. With one pagination ajax works perfectly but i have problems when i want to implement AJAX on second Laravel pagination. Does anyone can help me ?
First pagination
Second pagination
Controller
function successlogin(Request $request)
$posts= Post::orderby('created_at', 'desc')->paginate(3, ['*'], 'page_1s');
$documents= Document::orderby('created_at', 'desc')->paginate(2, ['*'], 'page_2s');
if ($request->ajax())
return view('presult', compact('posts'));
return view('main_page', ['posts'=>$posts,'documents'=>$documents]);
main_page
<section id="services">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: #d21826; font-weight: bold;">Vijesti</h2>
<hr class="my-4">
</div>
</div>
</div>
<div class="container">
@if(session('deletePost'))
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
session('deletePost')
</div>
@endif
<div id="tag_container">
@include('presult')
</div>
</div>
</section>
<section class="bg-primary" id="about">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: white; font-weight: bold;">Službeni Dokumenti</h2>
<hr class="light my-4">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-12 mx-auto text-center">
<div id="table_container" class="table-responsive">
@include('table')
</div>
</div>
</div>
</div>
@if (Auth::user())
<a href=" route('document.create')" class="btn btn-success" style="margin-right: 3px; border-radius:0px; ">Dodaj Vijest</a>
@endif
</section>
ajax_script for pagination
$(window).on('hashchange', function()
if (window.location.hash)
var page = window.location.hash.replace('#', '');
if (page == Number.NaN
);
$(document).ready(function()
$(document).on('click', '.pagination a',function(event)
event.preventDefault();
$('li').removeClass('active');
$(this).parent('li').addClass('active');
var myurl = $(this).attr('href');
var page=$(this).attr('href').split('page_1s=')[1];
getData(page);
);
);
function getData(page)
$.ajax(
url: '?page_1s=' + page,
type: "get",
datatype: "html"
)
.done(function(data)
$("#tag_container").empty().html(data);
location.hash = page;
)
.fail(function(jqXHR, ajaxOptions, thrownError)
alert('No response from server');
);
php ajax laravel
add a comment |
I have 2 LARAVEL paginations on one page, know i want to implement AJAX technology in order to achive paginations without reload of entire page. With one pagination ajax works perfectly but i have problems when i want to implement AJAX on second Laravel pagination. Does anyone can help me ?
First pagination
Second pagination
Controller
function successlogin(Request $request)
$posts= Post::orderby('created_at', 'desc')->paginate(3, ['*'], 'page_1s');
$documents= Document::orderby('created_at', 'desc')->paginate(2, ['*'], 'page_2s');
if ($request->ajax())
return view('presult', compact('posts'));
return view('main_page', ['posts'=>$posts,'documents'=>$documents]);
main_page
<section id="services">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: #d21826; font-weight: bold;">Vijesti</h2>
<hr class="my-4">
</div>
</div>
</div>
<div class="container">
@if(session('deletePost'))
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
session('deletePost')
</div>
@endif
<div id="tag_container">
@include('presult')
</div>
</div>
</section>
<section class="bg-primary" id="about">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: white; font-weight: bold;">Službeni Dokumenti</h2>
<hr class="light my-4">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-12 mx-auto text-center">
<div id="table_container" class="table-responsive">
@include('table')
</div>
</div>
</div>
</div>
@if (Auth::user())
<a href=" route('document.create')" class="btn btn-success" style="margin-right: 3px; border-radius:0px; ">Dodaj Vijest</a>
@endif
</section>
ajax_script for pagination
$(window).on('hashchange', function()
if (window.location.hash)
var page = window.location.hash.replace('#', '');
if (page == Number.NaN
);
$(document).ready(function()
$(document).on('click', '.pagination a',function(event)
event.preventDefault();
$('li').removeClass('active');
$(this).parent('li').addClass('active');
var myurl = $(this).attr('href');
var page=$(this).attr('href').split('page_1s=')[1];
getData(page);
);
);
function getData(page)
$.ajax(
url: '?page_1s=' + page,
type: "get",
datatype: "html"
)
.done(function(data)
$("#tag_container").empty().html(data);
location.hash = page;
)
.fail(function(jqXHR, ajaxOptions, thrownError)
alert('No response from server');
);
php ajax laravel
add a comment |
I have 2 LARAVEL paginations on one page, know i want to implement AJAX technology in order to achive paginations without reload of entire page. With one pagination ajax works perfectly but i have problems when i want to implement AJAX on second Laravel pagination. Does anyone can help me ?
First pagination
Second pagination
Controller
function successlogin(Request $request)
$posts= Post::orderby('created_at', 'desc')->paginate(3, ['*'], 'page_1s');
$documents= Document::orderby('created_at', 'desc')->paginate(2, ['*'], 'page_2s');
if ($request->ajax())
return view('presult', compact('posts'));
return view('main_page', ['posts'=>$posts,'documents'=>$documents]);
main_page
<section id="services">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: #d21826; font-weight: bold;">Vijesti</h2>
<hr class="my-4">
</div>
</div>
</div>
<div class="container">
@if(session('deletePost'))
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
session('deletePost')
</div>
@endif
<div id="tag_container">
@include('presult')
</div>
</div>
</section>
<section class="bg-primary" id="about">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: white; font-weight: bold;">Službeni Dokumenti</h2>
<hr class="light my-4">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-12 mx-auto text-center">
<div id="table_container" class="table-responsive">
@include('table')
</div>
</div>
</div>
</div>
@if (Auth::user())
<a href=" route('document.create')" class="btn btn-success" style="margin-right: 3px; border-radius:0px; ">Dodaj Vijest</a>
@endif
</section>
ajax_script for pagination
$(window).on('hashchange', function()
if (window.location.hash)
var page = window.location.hash.replace('#', '');
if (page == Number.NaN
);
$(document).ready(function()
$(document).on('click', '.pagination a',function(event)
event.preventDefault();
$('li').removeClass('active');
$(this).parent('li').addClass('active');
var myurl = $(this).attr('href');
var page=$(this).attr('href').split('page_1s=')[1];
getData(page);
);
);
function getData(page)
$.ajax(
url: '?page_1s=' + page,
type: "get",
datatype: "html"
)
.done(function(data)
$("#tag_container").empty().html(data);
location.hash = page;
)
.fail(function(jqXHR, ajaxOptions, thrownError)
alert('No response from server');
);
php ajax laravel
I have 2 LARAVEL paginations on one page, know i want to implement AJAX technology in order to achive paginations without reload of entire page. With one pagination ajax works perfectly but i have problems when i want to implement AJAX on second Laravel pagination. Does anyone can help me ?
First pagination
Second pagination
Controller
function successlogin(Request $request)
$posts= Post::orderby('created_at', 'desc')->paginate(3, ['*'], 'page_1s');
$documents= Document::orderby('created_at', 'desc')->paginate(2, ['*'], 'page_2s');
if ($request->ajax())
return view('presult', compact('posts'));
return view('main_page', ['posts'=>$posts,'documents'=>$documents]);
main_page
<section id="services">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: #d21826; font-weight: bold;">Vijesti</h2>
<hr class="my-4">
</div>
</div>
</div>
<div class="container">
@if(session('deletePost'))
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
session('deletePost')
</div>
@endif
<div id="tag_container">
@include('presult')
</div>
</div>
</section>
<section class="bg-primary" id="about">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading" style="color: white; font-weight: bold;">Službeni Dokumenti</h2>
<hr class="light my-4">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-12 mx-auto text-center">
<div id="table_container" class="table-responsive">
@include('table')
</div>
</div>
</div>
</div>
@if (Auth::user())
<a href=" route('document.create')" class="btn btn-success" style="margin-right: 3px; border-radius:0px; ">Dodaj Vijest</a>
@endif
</section>
ajax_script for pagination
$(window).on('hashchange', function()
if (window.location.hash)
var page = window.location.hash.replace('#', '');
if (page == Number.NaN
);
$(document).ready(function()
$(document).on('click', '.pagination a',function(event)
event.preventDefault();
$('li').removeClass('active');
$(this).parent('li').addClass('active');
var myurl = $(this).attr('href');
var page=$(this).attr('href').split('page_1s=')[1];
getData(page);
);
);
function getData(page)
$.ajax(
url: '?page_1s=' + page,
type: "get",
datatype: "html"
)
.done(function(data)
$("#tag_container").empty().html(data);
location.hash = page;
)
.fail(function(jqXHR, ajaxOptions, thrownError)
alert('No response from server');
);
php ajax laravel
php ajax laravel
edited Nov 13 '18 at 19:10
Nenad
asked Nov 13 '18 at 16:20
NenadNenad
648
648
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285236%2fhow-to-implement-ajax-on-multiple-laravel-pagination%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285236%2fhow-to-implement-ajax-on-multiple-laravel-pagination%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown