FAQ Topic - Why is my AJAX page not updated properly when using an HTTP GET request in Internet Expl

F

FAQ server

-----------------------------------------------------------------------
FAQ Topic - Why is my AJAX page not updated properly when
using an HTTP GET request in Internet Explorer?
-----------------------------------------------------------------------

Microsoft Internet Explorer caches the results of HTTP GET requests. To ensure that the
document is retrieved from the server, you will need to use the POST Method.

http://msdn2.microsoft.com/en-us/library/ms536648.aspx


--
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers. The sendings of these
daily posts are proficiently hosted by http://www.pair.com.
 
G

getsanjay.sharma

Either that or append a timestamp to your URL so that the results are
not cached. It has worked for me. Something like:

var url = 'action.do?t=' + (+new Date());
xhr.open('get', url, true);
xhr.send(null);
 
T

Thomas 'PointedEars' Lahn

Either that or append a timestamp to your URL so that the results are
not cached. It has worked for me. Something like:

var url = 'action.do?t=' + (+new Date());
xhr.open('get', url, true);
xhr.send(null);

That is only required for people who have servers that cannot
provide cache-controlling headers. Search the archives.


PointedEars
 
G

getsanjay.sharma

That is only required for people who have servers that cannot
provide cache-controlling headers. Search the archives.

PointedEars

So does this mean that what is specified in the FAQ and my me can be
easily corrected by setting the relevant cache headers in the response
header? I mean something like: response.setHeader("Cache-Control", "no-
cache") ?

Thanks and regards,
/~STS
 
T

Thomas 'PointedEars' Lahn

So does this mean that what is specified in the FAQ and my me can be
easily corrected by setting the relevant cache headers in the response
header? I mean something like: response.setHeader("Cache-Control", "no-
cache") ?

Yes, it can.


PointedEars
 
P

Peter Michaux

On said:
Either that or append a timestamp to your URL so that the results are
not cached. It has worked for me. Something like:

var url = 'action.do?t=' + (+new Date());

I have a vague memory that this is not necessarily sufficient because
the browser doesn't necessarily look at the query string when
determining whether or not to use the cache.

Better is to have the timestamp as part of the URL before the query
string

var url = 'action-' + (new Date()) + '.do';

The above is a good idea for static files like .js and .css where you
want to cache the files but then you want to have new versions
download.

For Ajax responses, if controlling the response headers with no-cache
is possible then it seems to be the most natural way to do things.

Peter
 
T

Thomas 'PointedEars' Lahn

Peter said:
I have a vague memory that this is not necessarily sufficient because the
browser doesn't necessarily look at the query string when determining
whether or not to use the cache.

With all due respect: user agents this broken do not deserve to be supported.
Better is to have the timestamp as part of the URL before the query
string

var url = 'action-' + (new Date()) + '.do';

The above is a good idea for static files like .js and .css where you
want to cache the files but then you want to have new versions download.

However, it would require server-side URL rewrite.
For Ajax responses, if controlling the response headers with no-cache is
possible then it seems to be the most natural way to do things.

Exactly.


PointedEars
 
R

Richard Cornford

Peter said:
On Nov 25, 5:47 am, (e-mail address removed) wrote:

I have a vague memory that this is not necessarily sufficient
because the browser doesn't necessarily look at the query
string when determining whether or not to use the cache.

That would be an inaccurate or false memory, or a memory of an unsubstantiated claim made by
someone who did not know what they were talking about. The query string for a GET request is
part of the URL and caching must consider the full URL in order to be operating correctly. I
have previously posted the relevant parts of the HTTP 1.1 specification in response to this
common misconception.
For Ajax responses, if controlling the response headers
with no-cache is possible then it seems to be the most
natural way to do things.

It is difficult to envision an environment where such control was not possible (except for toy
''web space' provided to users as part of their ISP account).

Richard.
 
P

Peter Michaux

Peter Michaux wrote:

It is difficult to envision an environment where such control was not possible

It depends greatly on the server-side programmers involved ;-)

Peter
 
G

getsanjay.sharma

However, it would require server-side URL rewrite.
So does it mean that each time a request comes from the client, I
would have to filter out the real URL / action URL before using it by
employing a mechanism like ServletFilter?

Thanks and regards,
/~STS
 
T

Thomas 'PointedEars' Lahn

So does it mean that each time a request comes from the client, I
would have to filter out the real URL / action URL before using it by
employing a mechanism like ServletFilter?

I don't know ServletFilter, but with Apache you would have to define
something along

RewriteEngine on
RewriteRule ^(.*/[^-]+)-\d{13,}(.*)$ $1$2 [last]


PointedEars

P.S.
Please include an empty line between quoted text and your text;
that makes your postings easier legible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top