【发布时间】:2015-06-11 16:38:23
【问题描述】:
在控制台中显示此消息
GET 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 和路由问题..
【问题讨论】:
-
你有什么错误?
-
什么是根名称?是ajax吗?
-
@Jocker 错误是 GET localhost/ajax/pagination?page=5 404(未找到)
-
手动转到localhost/ajax/pagination?page=5时的结果或返回值是什么?
-
我按照其他课程制作 L4.2 ajax 分页,我证明这段代码运行良好,但对我不起作用!
标签: ajax laravel laravel-4 pagination routing