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 694791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:53:34+00:00 2026-05-14T02:53:34+00:00

I have already implemented some AJAX pagination in my Rails app by using the

  • 0

I have already implemented some AJAX pagination in my Rails app by using the example code for the will_paginate plugin–which is apparently using Prototype.

But if I wanted to switch to using jQuery for future additions, I really don’t want to have the Prototype stuff sitting around too (yes, I know it’s possible). I haven’t written a lick of JavaScript in years, let alone looked into Prototype and jQuery… so I could use some help converting this bit into jQuery-compatible syntax:

document.observe("dom:loaded", function() {
  // the element in which we will observe all clicks and capture
  // ones originating from pagination links
  var container = $(document.body)

  if (container) {
    var img = new Image
    img.src = '/images/spinner.gif'

    function createSpinner() {
      return new Element('img', { src: img.src, 'class': 'spinner' })
    }

    container.observe('click', function(e) {
      var el = e.element()
      if (el.match('.pagination a')) {
        el.up('.pagination').insert(createSpinner())
        new Ajax.Request(el.href, { method: 'get' })
        e.stop()
      }
    })
  }
})

Thanks in advance!


Edit: Nick Craver’s answer got me 90% of the way there, so I just had to pick up enough jQuery to make the HTML element substitution. In place of the line where Nick had $.get($(this).attr("href"));, put this line:

$.get(this.href, null, function(data){ $(this).html(data); }, 'html');
  • 1 1 Answer
  • 1 View
  • 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-05-14T02:53:34+00:00Added an answer on May 14, 2026 at 2:53 am

    You can shorten this down a bit in jQuery to:

    $(function() {
      $('.pagination a').live('click', function(e) {
        $(this).parent('.pagination')
               .append("<img src='/images/spinner.gif' class='spinner' />");
        $.get($(this).attr("href"));
        return false;
      });
    });
    

    I’m not entirely sure about new Ajax.Request(el.href, { method: 'get' }) though, is this a script being requested? It looks like nothing’s being done with the content after return.

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

Sidebar

Related Questions

I've have already implemented pagination using the following code: public Paginacao<Anuncio> consultarPaginado(int pagina, Integer
i am using the code i have already implemented the table drag and drop
I have already implemented a functionallity, when keeper automatically moves using breadth first search
Before I start: I'm programming for Iphone, using objective C. I have already implemented
How can I write unit tests for existing and already implemented code which has
In my Android app, I have some data that needs to be synced daily
I am using History API for my web app and have one issue. I
In my previous projects, I have already implemented undo system in c++, and I
I need to implement compiler (lexical, syntax and semantic analyzers). I have already implemented
I am trying to implement a linux shell that supports piping. I have already

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.