Hitting browser "back" button shows JSON rather than HTML (using Rails & d3.js)

Viewed 1956

I'm generating a chart in Rails using a d3.js JSON callback like this:

View

d3.json(document.URL, function(data){ 
    // generate chart
}

Controller

def index
    respond_to do |format|
        format.html do
            # return the HTML
        end
        format.json do
            # return the JSON
        end
    end
end

All works fine. However when a user leaves this chart, and then navigates back to it using the "back" button on their brower they are presented with the JSON rather than the HTML.

Can you suggest how I might fix this?

2 Answers
Related