This article illustrates the laravel+jquery implementation of Ajax paging effect. Share to everyone for your reference, specific as follows:
JavaScript section:
_______________________//Listener to the [select from existing photos] button $ (' #photosModal '). On (' Shown.bs.modal ', function () {//Get the ' the ' the ' the ' the ' the ' the ' photos (paginated) getphotos (function (photosobj) {Displayphotos (photosobj)
;
});
}); /** * Get the photos paginated, and display them in the modal of selecting to existing photos * * @param page/functio N Getphotos (callback) {$.ajax ({type: "Get", DataType: ' json ', url:Routes.cms_photos,//This is a variabl E This holds my route URL data:{' page ': Window.current_page + 1//You might need to init this var on top of PA
GE (= 0)}}). Done (function (response) {var photosobj = $.parsejson (Response.photos);
Console.log (Photosobj);
Window.current_page = Photosobj.current_page; Hide the [Load more] button as 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 further] button $ (' #load-more-photos '). On (' click ', Function (e) {e.preventdefault ();
Getphotos (function (photosobj) {Displayphotos (photosobj);
});
});
PHP Controller section:
//_______________________
//...
$photos = $this->photo_repo->paginate ();
Return Response::json ([
' status ' => ' success ', '
photos ' => $photos->tojson (),
]);
More interested in laravel related content readers can view the site topics: "Laravel Framework Introduction and Advanced Course", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course ", PHP string (String) Usage summary," PHP+MYSQL Database operation Introduction Tutorial "and" PHP common database Operation Skills Summary "
I hope this article will help you with the PHP program design based on Laravel framework.