It seems that all the browsers other than Opera cache XHR requests in my Javascript program. The URL in the XHR request refers to a CGI program on the server which generates a different output everytime its called. B Is there a way in Javascript to make the browser not cache XHR requests?
+1
A:
Here you go! (This link helps you disable caching using xmlHttpReq
).
Or, you can use jQuery's Ajax feature, and disable caching by setting it's cache
to false
. Might be a cleaner option.
Chetan
2010-10-21 06:50:25
thanks, it works now!
Girish
2010-10-21 07:01:23
+1
A:
every ajax request you make, generate a unique value and add it to the ajax url as a query:
/example/url/post.php?rand=09809807896768
I tend to generate the cuurent unix timestamp in js and use that - ensures I do not get replicated unique stamps.
that way every request is unique and will not get cached. This is a simple but fairly common ajax trick - usually fixing IE and testing issues.
If you were to use jquery - it does this for you.
Glycerine
2010-10-21 07:02:39