Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
125 views
in Technique[技术] by (71.8m points)

java - How to disable Ajax caching?

I am having an issue with ajax caching, This was a problem in IE browser too but i fixed it by Writing the Following code.

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

But I see Safari4.0 on MAC is Caching the Ajax request(We have a requirment to support this). Fire Fox never a problem. Regarding this "Expire" i am setting it to -1, i see lot of places it is set 0 or some old date from past. Will it make a difference?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Send an extra parameter with your GET request that will never be the same, for example, the current timestamp. Something like:

url = url + '&nocache=' + new Date().getTime();

This will prevent caching.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...