shtalinberg / django-el-pagination

Django endless pagination tools. Ajax, multiple and lazy pagination, Twitter-style and Digg-style pagination.
MIT License
307 stars 71 forks source link

Twitter pagination: Old versions of pages appearing after first one #57

Open philgyford opened 7 years ago

philgyford commented 7 years ago

I'm having problems getting Twitter-style pagination working - it seems to load old versions of 'pages' after the first one.

The initial page load is fine, but when I click 'show more' the subsequent 'pages' use old versions of the template/HTML, and old versions of the items-per-page number. If I click far enough, and get to a 'page' I haven't visited before, then I get the correct, current template and items-per-page number. It's as if everything is cached somewhere, although I don't currently have any caching set up.

I'm using the local Django 1.10 development server. If I visit a page directly - i.e., go to /exhibitions/?page=2 in the browser - it uses the correct, current template.

My view:

from el_pagination.views import AjaxListView

class ExhibitionListView(AjaxListView):
    template_name = 'core/exhibition_list.html'
    page_template='core/includes/exhibitions.html'
    model = Exhibition
    ordering = 'begin_date'

My core/exhibition_list.html template:

{% include 'core/includes/exhibitions.html' %}

My core/includes/exhibitions.html template:

{% load el_pagination_tags %}

{% paginate 3,3 exhibition_list %}

{% for exhibition in exhibition_list %}
    <p>{{ exhibition.title }}</p>
{% endfor %}

{% show_more %}
philgyford commented 7 years ago

Ah, it seems to be the jQuery $.get() request caching the response in the browser.

In el-pagination.js, if I replaced line 65 with an $.ajax() request with cache: false, it works as expected. I replaced this:

$.get(context.url, data, function(fragment) {
    // ...
});

with:

$.ajax({
  url: context.url,
  data: data,
  cache: false,
  success: function(fragment) {
    // ...
  }
});

Is this expected behaviour? Is there an easy way to disable it?