在控制台中显示此消息
获取http://localhost/ajax/pagination?page=5 404(未找到)
查看页面(pages.post):
@foreach ($posts as $post)
<article>
<h2>{{ $post->title }}</h2>
</article>
@endforeach
{{ $posts->links() }}
<script>
$(document).ready(function() {
$(document).on('click', '.pagination a', function (e) {
getPosts($(this).attr('href').split('page=')[1]);
e.preventDefault();
});
});
function getPosts(page) {
$.ajax({
type:'GET',
url : '/ajax/pagination?page=' + page,
}).done(function (data) {
$('.posts').html(data);
location.hash = page;
})
}
</script>
路线:
Route::get('/ajax/pagination',array('before' =>'auth' ,
'uses'=>'CampaignsController@showPostspag'));
控制器:
public function showPostspag()
{
$posts = Address::paginate(5);
return View::make('pages.post')->with('posts',$posts);
}
我的错误在哪里?我认为那是ajax url和路由问题..
答案 0 :(得分:0)
试试这个..
如果&#34; ajax&#34;您的根目录意味着更新以下代码
function getPosts(page) {
$.ajax({
type:'GET',
url : 'pagination?page=' + page,
}).done(function (data) {
$('.posts').html(data);
location.hash = page;
})
}
路线:
Route::get('pagination',array('before' =>'auth' ,
'uses'=>'CampaignsController@showPostspag'));