所以,我试图用laravel进行ajax分页,有下拉列表,它搜索类别并显示它们并且有效但分页是问题,我想将类型和页面传递给url让它变得动态但是分页甚至没有响应,你能看一下代码吗?
使用数据过滤器设置数据
<div id="filterUrl" data-url="{{ route('admin_scat_test') }}" data-id='3'></div>
<select name="citylist" id="filterType" form="carform" onchange="loadCategory(this.value)">
@foreach($scattegories as $key=>$category)
<option value="{{ $key }}" data-id="{{ $key }}">{{ $category }}</option>
@endforeach
</select>
<div id="txtHint"><b></b></div>
试图分页
$(window).on('hashchange', function () {
page = window.location.hash.replace('#', '');
getProducts(page);
});
$(document).on('click', '.pagination a', function (e) {
e.preventDefault();
var page = $(this).attr('href').split('page=')[1];
location.hash = page;
});
function getProducts(page) {
var url = $("#filterUrl").data("url");
var type = $("#filterType").data("id");
console.log(type);
$.ajax({
url: url + '?type=' + type + '&page=' + page
}).done(function (data) {
$('#txtHint').html(data);
});
}