0
我知道如何在Laravel中进行分页,我根据它的文档尝试了它,并且它非常简单。但是,我在其一个视图上实现了一个Jquery自动完成功能,此时分页不起作用。你会如何实现这一目标?Paginate Laravel 5.2 with Jquery
jQuery的
$("#city_autocomplete").autocomplete({
source: '/lead-users/autocomplete',
minLength: 2,
select: function(event, ui) {
$("#city_autocomplete").val(ui.item.value);
}
});
控制器
$leads = LeadUser::where('gender', 'LIKE', '%'.$gender.'%')
->orderBy('first_name', 'ASC')
->paginate(20);
查看
<tbody>
@foreach($leads as $count)
<tr>
<td>{{ $count->getFullName() }}</td>
<td>{{ $count->email }}</td>
<td>{{ $count->city }}</td>
<td>{{ $count->state }}</td>
<td>{{ $count->getGender() }}</td>
<td>{{ $count->yesOrNo() }}</td>
</tr>
@endforeach
</tbody>
</table>
{{ $counts->links() }}
好吧,我更新我的Jquery
<script>
$(document).ready(function(){
$("#city_autocomplete").autocomplete({
source: '/lead-users/autocomplete',
minLength: 2,
select: function(event, ui) {
$("#city_autocomplete").val(ui.item.value);
}
});
$(window).on('hashchange',function(){
page = window.location.hash.replace('#','');
getItems(page);
});
$(document).on('click','.pagination a', function(e){
e.preventDefault();
var page = $(this).attr('href').split('page=')[1];
// getItems(page);
location.hash = page;
});
function getItems(page){
$.ajax({
url: '/lead-users/autocomplete?page=' + page
}).done(function(data){
$('#leads').html(data);
});
};
});
</script>
这只会为分页2(1,2,3,4,5,6),其余部分将不会redirect.It不更改URL的浏览器,但没有任何反应的观点
city=Fremont#2
city=Fremont#3
city=Fremont#4