I'm just starting with Ajax. and I'm having a conceptual problem.
I have a form which submits a query, using Ajax. The Ajax is called via "onclick", so the page does not replot (of course). The called JSP file does the database query, formats the results into a table, and returns the table as a string of HTML code.
The Ajax routine then puts the generated code in the proper DIV, and ta-da, results! So far, so good.
But if the user hits "Refresh", away the results go!
Question: how do I make the results "stick", so they're properly recognized by Reload? Or is that even possible?
The reason that the results "disappear" is that when the browser reloads the original page from the server, it has no record of the user's query. The answer is to save the state of the page. This is probably best done with cookies for the present, although HTML5 will give you access to local storage that could be used for this purpose as well.
The page would need to check for the presence of your cookie, and then use the information it contains to re-send the query to your JSP script and then incorporate the data into the page as you would if the user had done a new manual query.
This isn't ordinarily an issue that I'd say you need to be overly concerned with. It's pretty rare for users to do a refresh in this kind of situation unless there are other issues with the page, such as some components not loading properly or the layout gets scrambled when they resize their browser window. So, if you've got confidence in those aspects, you can be less concerned about users doing a refresh. Good luck!