Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8096481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:27:49+00:00 2026-06-05T21:27:49+00:00

I have a paginated collection that could be simultaneously making multiple fetch()es. E.G. a

  • 0

I have a paginated collection that could be simultaneously making multiple fetch()es. E.G. a user could click on ‘page 1’ see a ‘Loading…’ message then click on ‘page 2’ before page 1 loads, which would fire off another fetch() request (sending down a different page param obviously). Hopefully that makes sense. I handle this within a View (Coffeescript):

render: ->
  if @collection.hasPage()
    # render the view
  else
    el.append '<h3>Loading...</h3>'

    @collection.fetch
      success: (coll, resp) => @render()

However, if I click on page 1, then page 2 before page 1 loads, the success callback for page 1 ends up being called twice (so three success() calls overall). The success() callbacks get called in this order: page 1, page 2, page 1

Why is this happening? Should I be handling this with events? Should I not allow multiple fetch()es simultaneously? Thanks for the help.

UPDATE

This is how I’m doing it now:

initialize: ->
  @page = @collection.page

render: ->
  if @collection.hasPage(@page)
    #render
  else
    el.append 'Loading...'

    @collection.fetch
       success: (coll,resp) =>
         # do some stuff with coll
         if @page == @collection.page
           @render()

Seems to work…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:27:51+00:00Added an answer on June 5, 2026 at 9:27 pm

    This is why it happens (at least according to my logic):

    1. Render is called -> a fetch for page 1 is fired
    2. User clicks page 2
    3. Render is called -> a fetch for page 2 is fired
    4. The fetch from first call to page 1 returns -> success: (coll, resp) => @render()
    5. WHAM BAM Render is called AGAIN -> page hasn’t been loaded so…
    6. Fetch is called for the 3rd time and for page 1
    7. Somewhere around here the call for page 2 returns

    And you definitely should handle this with events as the problem is caused by your render function doing the fetching and the drawing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of people that is paginated with will_paginate @people = Person.paginate
For some reasons, my will_paginate collection is stuck on page 2. I have the
I have a DIV that contains paginated results of a MySQL query. I was
I have a method that does a paginated find call like.. 1 coll =
I have a simple image gallery that I've paginated, and I want to to
I have a page the displays messages grouped by date, and paginated via AJAX.
I have a page that has to render a huge set of query results
I have a page that has a list of Hibernate entities that is loaded
So I have a search form that returns a Kaminari paginated array. The first
I have some photos that are split on successive pages through will_paginate plugin. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.