0

On page load, I do an ajax call to populate a <select>-element. The options of the <select>-element are stored in a database.

This works fine, but I'm getting different behaviors in different browsers, due to bfcache, when going back to the page using the back button:

In safari, it works as expected: after clicking the back button, the option I selected is still selected. This is because safari remembered my state and didn't do the ajax call again.

In chrome, however, this option I selected isn't selected. That's because Chrome does the ajax call again. While it has the possibility to remember the selected option in forms, it can't do that in my case because the ajax call is executed again.

Anyone has a possible solution for this? Is there a way to make Chrome behave like safari, so that it doesn't execute all the javascript again?

binoculars
  • 2,226
  • 5
  • 33
  • 61
  • Can store the state in localStorage – charlietfl Dec 31 '16 at 15:45
  • True, but the ajax call will still execute. So this would mean I have to wait for the ajax call to finish, and then use the localStorage to select the correct option. This is my plan B, because I don't like the fact that in some browsers, the ajax call isn't executed, while in others it is. – binoculars Dec 31 '16 at 15:48

0 Answers0