homepage Welcome to WebmasterWorld Guest from 54.166.8.138
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Newby: Ajax-generated code goes away on refresh.
ajax javascript tables
wilsoncpu




msg:4481327
 4:48 pm on Aug 2, 2012 (gmt 0)

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?

 

rainborick




msg:4481353
 5:30 pm on Aug 2, 2012 (gmt 0)

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved