The content created dynamically did not appear when the user clicks on the rear rails


I've got a page with cascading drop down lists (the available options of one drop down list is determined by the selection of another). I was an ajax call to fill this second select:

    url: "/sport_types/"+$(this).val()+"/leagues"
    dataType: "json"
    success: (data) ->
      $(".league_selector option").remove()
      row = "<option value=\"\">Choose a League...</option>"
      $.each data, (i, j) ->
        row = "<option value=\"" + + "\">" + j.league_name + "</option>"

This works fine, but if a user clicks the back button on their browser, this dynamically generated content is not loaded.

I'm running a rails app, just in case there's an easy way to handle this in rails, awesome. If not, any good ol' HTML/jQuery tricks would be greatly appreciated.

Hitting the back button in the browser is equivalent to a page refresh , so obviously you HTML will be defaulted to the normal state.

If you wish this approach to work you have to store the data either in a cookie or a session and populate in on refresh..