views:

134

answers:

2

I have the following code

$.ajax({type: "GET",
  url: "/" + filename,
  dataType: "xml",
  cache: "false",
  success: function(xml)
{
    /* Parsing code here */
}});

In Chrome etc the requests are not cached, however they are in IE. Am I constructing my request properly?

A: 

Perhaps it is the mimetype of the xml file you are returning? http://www.nerdydork.com/ie-json-caching-bug.html

One commenter on my blog suggested adding a time string to the json request:

I’m not going to trust in setting the cache to off in .ajaxSetup….

So just add a time string at the end of each json request, e.g.

$.getJSON( ‘/url/’, { data: 123, t: (new Date()).getTime() }, function(data) { //do whatever } );

Dustin
+4  A: 

cache should be a boolean, not a string:

$.ajax({type: "GET",
  url: "/" + filename,
  dataType: "xml",
  cache: false,
  success: function(xml){
    /* Parsing code here */
  }  
});
Matt
+1 a string `"false"` will be interpreted as `true` if not compared using `===`.
Pekka
@Pekka - that's true, but in this specific case, [jQuery DOES compare with ===](http://github.com/jquery/jquery/blob/master/src/ajax.js#L261), however it only attempts to avoid cache if `s.cache === false` (but of course, "false" === false => false)
Matt
@Matt ah! Good catch.
Pekka
Good cache I mean catch
James Westgate
@James: Good job you choose programming over comedy as a career path. :P
Matt
It was the bool thing, changing from `"false"` to `false` worked. ta
Chris