3

I can't find the way to turn off browser (and sometimes server "304") cache in GCL AJAX calls, like I've done in jQuery.

$.ajax({
  url: "test.html",
  cache: false,
});

Maybe I can control headers somehow?

I do not appreciate answers like adding a random string to a GET paramether manually. Like:

requestObject.send("/feed/get?id=" + id + '&nocache=' + new Date().getTime());
Dan
  • 48,995
  • 35
  • 110
  • 141

2 Answers2

2

Cache option in $.ajax puts a timestamp in a GET parameter.

However, you could put Cache-Control: no-cache in the request headers when you are calling the send() method.

Seyeong Jeong
  • 9,234
  • 2
  • 25
  • 38
  • Could you please add some code sample? I really can't find how to add `cache-control` – Dan Dec 01 '11 at 23:38
  • Try: `goog.net.XhrIo.send(url, opt_callback, opt_method, opt_content, {'Cache-Control': 'no-cache'}, opt_timeoutInterval)` – Seyeong Jeong Dec 01 '11 at 23:57
  • Thanks for that code sample! (PS: how nice jQuery code looks compared to GCL) – Dan Dec 02 '11 at 12:03
  • This question would help a bit clarifying optional parameters: http://stackoverflow.com/questions/8356227/skipping-optional-function-parameters-in-javascript – Dan Dec 02 '11 at 12:28
0

Assuming you are using xhrio to do the ajax, another way to do it is to set the header after you instantiate the xhrio.

var requestObject = new goog.net.XhrIo();
requestObject.headers.set('Cache-Control', 'no-cache');
goog.events.listen(requestObject, goog.net.EventType.COMPLETE, function(e) {
    var obj = this.getResponseJson();
}); 
requestObject.send('http://example.com/jsoncontentsource'); 
Cheeso
  • 180,104
  • 92
  • 446
  • 681
  • Sadly, this doesn't work for me. Even when setting the headers, IE9 seems to cache the request. Only the QueryString seems to work :( – monzonj Jan 14 '13 at 08:30