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()); 

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Could you please add some code sample? I really can't find how to add cache-control
Try: goog.net.XhrIo.send(url, opt_callback, opt_method, opt_content, {'Cache-Control': 'no-cache'}, opt_timeoutInterval)
Thanks for that code sample! (PS: how nice jQuery code looks compared to GCL)
This question would help a bit clarifying optional parameters: stackoverflow.com/questions/8356227/…
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'); 

1 Comment

Sadly, this doesn't work for me. Even when setting the headers, IE9 seems to cache the request. Only the QueryString seems to work :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.