i我的laravel项目我正在使用laravel的分页。并通过ajax呼叫,但是现在我想添加排序搜索和其他内容。所以我想要我的URL喜欢http://localhost:8000/test/stites?page = 2& stort = name& order = asc = asc但是我会像http://localhost:8000/test/stites#?page = 2 = 2,我如何删除#wich来自laravel caode。
$sites = DB::table('to_jobs')
->select(array(
'to_jobs.rec_id',
'to_jobs.contarct_code',
'to_jobs.job_num',
'to_sites.site_name',
'to_sites.postcode',
'to_sites.site_id'
))
->leftjoin('to_sites', 'to_jobs.fk_site_id', '=', 'to_sites.site_id')
/* ->join(DB::raw('(SELECT rec_id FROM to_jobs LIMIT 299990, 10) AS t'), function($join) {
$join->on('t.rec_id', '=', 'to_jobs.rec_id');
})*/
->paginate(10);
if (Request::ajax()) {
return Response::json(View('sites/site_data',compact('sites'),compact('user_data'))->render());
}
我是否需要更改Render()。
$(document).ready(function() {
$(document).on('click', '.pagination a', function (e) {
getPagePosts($(this).attr('href').split('page=')[1]);
e.preventDefault();
});
$(document).on('click', '.sorting', function (e) {
getSortPosts($('.pagination .active span').html(),$(this).attr('aria-label'),$(this).attr('aria-sort'));
e.preventDefault();
});
});
function getPagePosts(page) {
$.ajax({
url : '?page=' + page ,
dataType: 'json',
}).done(function (data) {
$('.posts').html(data);
location.hash= '?page=' + page ;
}).fail(function () {
alert('Posts could not be loaded.');
});
}
谢谢,我在location.hash的这里找到了它。但是最近我知道,如果我删除.hash。您能解释一下为什么不添加哈希,如果不添加hash,则不添加,然后不刷新页面
您只需删除脚本中的行。
`location.hash= '?page=' + page;`