[英]Laravel5 pagination with Jquery Ajax
我正在使用Laravel5分頁。 我添加了一些Ajax代碼,因為當我單擊“下一步”按鈕時,不需要刷新頁面。
我的問題是,當我單擊“下一步”按鈕時,我的頁面正在刷新。 請幫助我找到這個問題。 我的代碼和屏幕截圖如下。
在firefox firebug控制台中,顯示一些錯誤“ TypeError:Window.getDefaultComputedStyle的參數1不是對象”。
js #abilitytest:單擊函數以在引導模型中顯示數據
$( "#abilitytest" ).click(function() {
$.post("/abilitytest", function(response){
$( "#abilityQuestions" ).html(response);
});
});
$('.pagination a').on('click', function (event) {
event.preventDefault();
var page = $(this).attr('href');
console.log(page);
alert('hai');
});
控制者
$abilitytests = Abilitytest::simplePaginate(1);
return view('test.abilitytestmodal',['abilitytests' => $abilitytests]);
在$('.pagination a')
上綁定事件偵聽器可能會遇到一些麻煩?
嘗試
$(document).on('click', '.pagination a', function(event){
代替
$('.pagination a').on('click', function (event) {
目前,我正在使用laravel分頁內置函數simplePaginate()
。
Abilitytest::simplePaginate(1)
,分頁的ul類將為class =“ pager”。 <ul class="pager">
。
如果我們使用laravel內置函數paginate()
,則分頁的ul類將為class =“ pagination”。
所以問題是我在JS文件“ <ul class="pagination">
“中使用了錯誤的類名。
所以我的代碼是
$('.pager a').on('click', function (event) {
event.preventDefault();
var page = $(this).attr('href');
console.log(page);
alert('hai');
});
謝謝
您可以像這樣在准備好的文檔上使用jQuery
$(document).ready(function (){ $('.pagination a').on('click', function (event) {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.