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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:58:11+00:00 2026-06-07T05:58:11+00:00

I’m using JQuery to implement pagination in my rails app, and have run into

  • 0

I’m using JQuery to implement pagination in my rails app, and have run into a problem where sometimes rails fails to render the page content when I hit back in my browser, and instead it dumps the raw Javascript into my browser window. Here’s a quick look at what I’m using:

pagination.js:

if (history && history.pushState) {
  $(function () {
    $('.pagination a').live("click", function () {
      $.ajax({url: this.href, dataType: "script", cache: true});
      history.pushState(null, document.title, this.href);
      $("html, body").animate({ scrollTop: 0 }, 300);
      return false;
    });

    $(window).bind("popstate", function() {
      $.ajax({url: location.href, dataType: "script", cache: true});
    });
  });
}

And in my view, index.js.erb:

$("#products").html("<%= escape_javascript(render("products")) %>");

It works some of the time, but often when hitting the back button the JS is dumped into my browser window without being evaluated/rendered. It looks like this (in my browser):

$("#products").html("<table class=\"table table-striped\">\n<thead>\n<tr>\n<th>Products

…etc. I’m not sure exactly what is failing. Any ideas?

  • 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-07T05:58:12+00:00Added an answer on June 7, 2026 at 5:58 am

    The paths requested by your browser look like

    • /products
    • /products?page=1
    • /products?page=2

    Depending on whether /products?page=2 was browsed to ‘manually’ or via ajax you render the js version or the plain version. When you hit the back button you may just get what is in the browser’s cache which could be either of those two versions depending on what your previous navigation history was.

    In order for this to work properly you want the browser to maintain two separate versions of the cache. One way of doing this is by adding an extra parameter when you make your ajax request:

    $('.pagination a').live("click", function () {
      $.ajax({url: this.href, dataType: "script", cache: true, data: {'ajax_paginate': true});
      ...
    });
    

    jquery-pjax already does this, and if you use the pjax-rails plugin the magic cache-separating parameter will be stripped for you automatically.

    You’ll want to empty your browser cache before you try this out – you’ve probably already got a bunch of bad data in the cache.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have thousands of HTML files to process using Groovy/Java and I need to

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.