1

I am new to CakePHP. I have installed CakePHP 3.2.10.

I have implemented simple AJAX calls. I have also implemented pagination in normal view.

Now I want to show records, loading with AJAX and using pagination.

Can anyone guide me how to go about doing this?

I have referred to the cookbook but did not get proper information.

Do I create a normal action and view with pagination code ?

Warren Sergent
  • 2,542
  • 4
  • 36
  • 42
Bhargav S
  • 23
  • 7
  • Start from: make it work without ajax (which should be easy, because it should already be work). Your code needs to be in the question for readers to help you. – AD7six Jun 10 '16 at 10:14
  • [Here](http://sandbox.dereuromark.de/sandbox/ajax-examples) are some examples along with lots of more code and a blog post to find more about AJAX and CakePHP. – mark Jun 22 '16 at 00:00

1 Answers1

1

Simply, you can use liveQuery Javascript library. you can download from here

  1. And add this library code in your CakePHP template layout in
  2. Wrap your listings and pagination links in div tag apply id="wrapper".
  3. add this function in common javascript code which must be load in page end before end of body tag

Add Below Code in Javascript

function ajaxPageLoader(request_url) {
        console.log("Content loading from : "+request_url);
        $("#wrapper").load(request_url + " #wrapper", function() {
            window.history.pushState({}, "", request_url);
            console.log("Content loaded");
        });
    }
$(document).ready(function(){
       $('your_pagination_link_selector').livequery(function() {
            $(this).unbind('click').bind('click', function(e) {
                e.preventDefault();
                ajaxPageLoader($(this).attr('href'));
                return false;
            })
       });
    });
Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42