Hitting browser "back" button shows JSON rather than HTML (using Rails & d3.js)
charts, d3.js, javascript, json, ruby-on-rails
Solution
d3.json(window.location.pathname + ".json" + window.location.search.substring(0), function(json){
// generate chart
}
As inspired by this question.
Problem
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?