I have a web page that queries a database using getJSON as soon as the page is loaded, in order to populate a drop down box. Then when the user selects an option from this initial box, a second getJSON call is made to populate the second drop down with data that is relevant. In an attempt to save calls to the database (especially if the user keeps toggling values in the first combo box), I'm thinking of saving the data for the drop down menus in cookies/ But I'd like to do something where the cookie is only good for the current session... because technically, it is possible that the data in the database will change. It won't change often... but it can change.
I found the following post:
jquery save json data object in cookie
which I'm thinking of trying out.
The logic I'm thinking of implementing would be something like this:
a. on document ready, check if cookie exists. If not, query db and get data. Create cookie b. when session is killed, kill cookies.
My questions are as follows:
- Is this the right approach?
- how can I modify the example in the above stackoverflow post so that the cookies are only good for the current session?
FYI. The target browser is IE 9.
Thanks.
EDIT 1:
I found this post for creating session cookies with jquery: create session based cookie, jquery I'll give that a try.
EDIT 2:
I think I'll also check out sessionstorage while i'm at it.