我有laravel应用程序,并使用laravel创建简单的搜索,此搜索paginate
Ajax
一切都很好,但是当搜索某些内容并单击分页的第二页时,它会显示所有users
。
我进行搜索,发现将此代码添加到我的代码中:
{{$users->appends(request()->query())->links()}}
但是这里我将Ajax与分页一起使用!所以我该如何解决?
链接:
。#1表示首页,等等。
Ajax代码:
<script>
$(window).on('hashchange', function() {
if (window.location.hash) {
var page = window.location.hash.replace('#', '');
if (page == Number.NaN || page <= 0) {
return false;
} else {
getPosts(page);
}
}
});
$(document).ready(function() {
$(document).on('click', '.pagination a', function (e) {
getPosts($(this).attr('href').split('page=')[1]);
e.preventDefault();
});
});
function getPosts(page) {
$.ajax({
url : '?page=' + page,
dataType: 'json',
}).done(function (data) {
$('.posts').html(data);
location.hash = page;
$('html, body').animate({ scrollTop: 0 });
});
}
</script>
url
更改为此:url:"search?q="+ "{{ Input::get('q') }}" +"&page="+page,