views:

16

answers:

2

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
thanks, it works now!
Girish
+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
Thanks. I tried adding new Date().getTime() that worked too.
Girish