This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I was playing with a very elementary AJAX example recently (user registration on a website) and I noticed that once a server-side asynchronous hit has been made for a particular "username" input-value, IE (I am not sure about other browsers) would not even make another HTTP Request for the same "username" input value next-time, it just returns the previous result. This led me to the belief that some amount of caching is involved here.
I am aware that the way out of this problem is probably the same as preventing browser-caching for any dynamic page (link for the un-inited), but I want to know where exactly does this caching happens, is it being done by the AJAX engine or is it similar to normal browser caching?
Thanks for your time and best wishes for the success of the book.
I too thought that the browser-caching has some effects, but after setting the browser-caching effects like "expires, no cache etc.," I didnt had this problem. I have a case where AJAX reads a dynamically generated xml file for every onChange event input. So far this is working fine in both IE and mozila.
I have another case where AJAX reads a static xml file on page load event. If i change the xml file content, mozile shows it fine, but IE seems to read the old xml file for a while.
Yes, at times browsers will cache the request and not make a new request even though we may want it to. This is controlled by the browser itself and not the XMLHttpRequest object.
You're on the right track for avoiding it. The techniques I'm aware of are setting the headers to "no cache" and "expires" and also to append a unique timestamp to the end of every URL that's used in an Ajax request, as the unique URL will force the browser to perform a fresh request each time.
Ryan Asleson<br />Co-Author, <a href="http://www.amazon.com/Foundations-Ajax-Foundation-Ryan-Asleson/dp/1590595823/sr=1-1/qid=1158926537/ref=pd_bbs_1/002-7412154-2924860?ie=UTF8&s=books" target="_blank" rel="nofollow">Foundations of Ajax</a> and <a href="http://www.amazon.com/Pro-Ajax-Java-Frameworks/dp/1590596773/ref=sr_11_1/002-7412154-2924860?ie=UTF8" target="_blank" rel="nofollow">Pro Ajax and Java Frameworks</a><br /><a href="http://taconite.sf.net" target="_blank" rel="nofollow">Taconite</a> Lead Developer
Am I right in thinking that another way to avoid this problem is to use POST rather than GET for sending your requests?
Since POST is designed to change the state on the server, the browser should send every request, even if the URL and data are exactly the same as a previous request.
Chihuahua - Ajax-powered online word puzzle, <a href="http://chi.lexigame.com" target="_blank" rel="nofollow">http://chi.lexigame.com</a> <br />Letterbox Word Game Online, <a href="http://letterbox.lexigame.com" target="_blank" rel="nofollow">http://letterbox.lexigame.com</a> <br />Lexi Word Game for Java-enabled phones, <a href="http://www.lexigame.com" target="_blank" rel="nofollow">http://www.lexigame.com</a>
Hi, I am facing a similar problem. I want to refresh the data on my page every few seconds. But the AJAX script fetches the same data every time. I have used the random function in my servlet. The servlet shows a random number each time, but somehow the JSP calling the servlet through AJAX, is unable to do so.
It keeps on displaying the same data again and again.
I have tried using response.setHeader(" ..."), but that prevents any data from being displayed on the JSP. I am using IE.
on similar requirement I need to fetch tooltip only if it's changed from what it was displayed (cached) first time to avoid unnecessary server trip if content is not changed. any advise?
Joined: Nov 08, 2001
Joined: Dec 16, 2004
thanks eric. however I don't know whether I got your idea correctly or I didn't clearly mention my requirement.
I do following -grab and display tooltip(AJAX call) on mouse hover on a particular item. -you are saying, i should store this tooltip value in JS array? -but even if I store first time fetched value in array, how do I know whether value on server has changed or not for this tooltip (data for tooltip is being feed by another application, which can alter tooltip data on the fly while first app is running and displaying tooltip).