顯示在控制檯此消息Laravel 4.2 AJAX分頁路由問題
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'=>'[email protected]'));
控制器:
public function showPostspag()
{
$posts = Address::paginate(5);
return View::make('pages.post')->with('posts',$posts);
}
我的錯誤在哪裏?我認爲這是一個AJAX網址和路由問題..
什麼你有錯誤? –
什麼是根名?這是阿賈克斯? –
@Jocker錯誤是GET http:// localhost/ajax/pagination?page = 5 404(Not Found) –