Laravel+jquery implement Ajax paging effect _php instance

Source: Internet
Author: User
Tags json smarty template

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.