3

I'm using Kaminari for pagination. And here is the code which i'm using for infinite scroll:

jQuery(function() {
   if ($('.pagination').length) {
     $(window).scroll(function() {
       var url;
       url = $('.pagination .next_page').attr('href');
       if(url && $(window).scrollTop()>$(document).height()-$(window).height()-50)
       {
         $('.pagination').text("Fetching more products...");
         return $.getScript(url);
       }
    });
    return $(window).scroll();
}

The above code I've written in a document.ready function. And then this code is written in .js.erb file

$("#container1").append("<%= escape_javascript(render 'shirts/first')%>");
    <% if @first.next_page %>
       $('.pagination').replaceWith("<%= j paginate @first %>");
    <% else %>
       $('.pagination').remove();
    <% end %>
    <% sleep 1 %>
});

But I'm not getting the infinite scroll. Can someone guide me as where I'm going wrong?

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Raghuveer
  • 397
  • 2
  • 8
  • Does the pagination work at all? (without the automatic infinite scroll). Also, define "not getting infinite scroll". Any errors? What happens with your implementation? – KappaNossi Feb 04 '14 at 13:12
  • Nothing. Only the first page loads up. Remainning aren't. – Raghuveer Feb 04 '14 at 13:24
  • Then test it with normal pagination buttons first - just to check whether your code for getting a different page works. – KappaNossi Feb 04 '14 at 14:55
  • It is working for normal pagination. I get my next page, but when I try the above code it doesn't work! – Raghuveer Feb 05 '14 at 05:02
  • Well I can't see any apparent errors in your JS. You need to try to isolate the problem. To do that, you could debug your rails app and set a breakpoint in the controller pagination method and see if the call actually reaches this point. Either way, you need to debug the javascript on the page. Use Firebug or similar plugins for this to set breakpoints in either piece of code. Maybe the JS log of the browser already offers some insight (Strg+Shift+J in Firefox) – KappaNossi Feb 05 '14 at 08:44
  • 1. can you confirm if your code is executing $.getScript(url)? 2. i find that sometimes it's easier to just insert some console.log("test!") messages into your js to see what parts are executing or not, if you don't find anything through breakpoints or other debugging strategies. – jay Feb 17 '14 at 05:19
  • What do you mean by not working ? – 0bserver07 Mar 03 '14 at 23:58

0 Answers0