Laravel+jQuery實(shí)現(xiàn)AJAX分頁效果
本文實(shí)例講述了Laravel+jQuery實(shí)現(xiàn)AJAX分頁效果。分享給大家供大家參考,具體如下:
JavaScript部分:
//_______________________ // listener to the [select from existing photos] button $('#photosModal').on('shown.bs.modal', function () { // get the first page of photos (paginated) getPhotos(function(photosObj){ displayPhotos(photosObj); }); }); /** * get the photos paginated, and display them in the modal of selecting from existing photos * * @param page */ function getPhotos(callback) { $.ajax({ type: "GET", dataType: 'json', url: Routes.cms_photos, // this is a variable that holds my route url data:{ 'page': window.current_page + 1 // you might need to init that var on top of page (= 0) } }) .done(function( response ) { var photosObj = $.parseJSON(response.photos); console.log(photosObj); window.current_page = photosObj.current_page; // hide the [load more] button when all pages are loaded if(window.current_page == photosObj.last_page){ $('#load-more-photos').hide(); } callback(photosObj); }) .fail(function( response ) { console.log( "Error: " + response ); }); } /** * @param photosObj */ function displayPhotos(photosObj) { var options = ''; $.each(photosObj.data, function(key, value){ options = options + "<option data-img-src='"+value.thumbnail+"' value='"+value.id+"'></option>"; }); $('#photos-selector').append(options); $("select").imagepicker(); } // listener to the [load more] button $('#load-more-photos').on('click', function(e){ e.preventDefault(); getPhotos(function(photosObj){ displayPhotos(photosObj); }); });
php控制器部分:
//_______________________ //... $photos = $this->photo_repo->paginate(12); return Response::json([ 'status' => 'success', 'photos' => $photos->toJson(), ]);
更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《smarty模板入門基礎(chǔ)教程》、《php日期與時間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Laravel框架的PHP程序設(shè)計(jì)有所幫助。
- Laravel5.5 手動分頁和自定義分頁樣式的簡單實(shí)現(xiàn)
- PHP框架Laravel插件Pagination實(shí)現(xiàn)自定義分頁
- laravel自定義分頁效果
- laravel自定義分頁的實(shí)現(xiàn)案例offset()和limit()
- laravel實(shí)現(xiàn)分頁樣式替換示例代碼(增加首、尾頁)
- Laravel手動分頁實(shí)現(xiàn)方法詳解
- Laravel框架執(zhí)行原生SQL語句及使用paginate分頁的方法
- laravel手動創(chuàng)建數(shù)組分頁的實(shí)現(xiàn)代碼
- Laravel框架自定義分頁樣式操作示例
相關(guān)文章
php檢測用戶是否用手機(jī)(Mobile)訪問網(wǎng)站的類
php檢測用戶是否用手機(jī)(Mobile)訪問網(wǎng)站的類,引入這個類就可以直接使用了,程序基于MIT License協(xié)議開源,使用方法在下面2014-01-01PHP仿博客園 個人博客(1) 數(shù)據(jù)庫與界面設(shè)計(jì)
自學(xué)PHP大半年多了,斷斷續(xù)續(xù)地,但是最終還是堅(jiān)定了我的想法,將PHP繼續(xù)下去,所以寫這個PHP的博客是為了找個穩(wěn)定的 PHP工作,不求工資多高,但求一收留之地2013-07-07PHP守護(hù)進(jìn)程化在C和PHP環(huán)境下的實(shí)現(xiàn)
這篇文章主要介紹了PHP守護(hù)進(jìn)程化的實(shí)現(xiàn)的方法以及原理過程,以及在C環(huán)境和PHP環(huán)境下實(shí)現(xiàn)的代碼,喜歡的朋友收藏一下。2017-11-11PHP+Jquery與ajax相結(jié)合實(shí)現(xiàn)下拉淡出瀑布流效果【無需插件】
這篇文章主要介紹了PHP+Jquery與ajax相結(jié)合實(shí)現(xiàn)下拉淡出瀑布流效果【無需插件】的相關(guān)資料,需要的朋友可以參考下2016-05-05詳解php用curl調(diào)用接口方法,get和post兩種方式
本篇文章主要介紹了詳解php用curl調(diào)用接口方法,get和post兩種方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01PHP之浮點(diǎn)數(shù)計(jì)算比較以及取整數(shù)不準(zhǔn)確的解決辦法
這篇文章主要介紹了PHP之浮點(diǎn)數(shù)計(jì)算比較以及取整數(shù)不準(zhǔn)確的解決辦法,代碼超簡單,需要的朋友可以參考下2015-07-07