aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes AJAX requests on page reload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "AJAX requests on page reload" Watch "AJAX requests on page reload" New topic
Author

AJAX requests on page reload

igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
Hello, I have a JSP page page on which I am running some AJAX functions. ie. on page load, an AJAX function which queries the JSP page for the value of a String called currentMessage starts running. This works very well and displays the current value of the String currentMessage as I have requested it to do.

The problem arises when I reload the JSP page using my browsers refresh button or reload. In the beginning of my JSP code, I set the value of currentMessage to "", which is basically an empty string. But even when I reload the page, thinking that everything has started anew, the value of currentMessage still remains the last value it was set to before the page reload. How can I make sure that the value of currentMessage is reset each time the page reloads. Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
It should recall the function. Is it possible to see some code.

Eric
igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
OK, first here is the javascript:



CounterThread ensures that the get method is run every 2 seconds to get the current value of currentMessage.

In my JSP/Servlet, this gives prints the value of currentMessage:




Of course the value of currentMessage is changed during runtime of the page. But when I refresh the page, shouldn't the page begin with the new value for currentMessage?

Of course, the body element of the HTML component of my JSP page loads the retrieveURL() function once it starts.

Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
try adding an alert message inside your funciton retrieveURL() and see if it is being called when the page is being refreshed. The code looks fine to me.

Eric
igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
Hi Eric, just have one more question. The page you're seen is being deployed as a war file. WHen it's just a webapp on tomcat (in a folder) the ajax call works, but if it is deployed in a war file the AJAX calls don't work anymore and nothing is displayed. Looking at the code, is there any way to make AJAX calls work from within a WAR file? THanks.
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
Being deployed as a WAR file shouldn't make any difference whatsoever - after all, Tomcat expands the WAR into a folder anyway. Did you make sure to delete the web-app's folder before you put in a new WAR? Tomcat doesn't usually do that by itself.

And this,

response.setHeader("Cache-Control", "no-cache");

may not be enough. When I want to make absolutely certain the page isn't cached, I do the following:



-Yuriy
[ July 21, 2005: Message edited by: Yuriy Zilbergleyt ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AJAX requests on page reload