views:

396

answers:

4

Hi,

for some reason, IE6/7 is caching the ajax call that returns a json result set back.

My page makes the call, and returns a json result which I then inject into the page.

How can I force IE6/7 to make this call and not use a cached return value?

+1  A: 

You might want to add

Cache-Control: no-cache

to your HTML response headers when you're serving the JSON to tell the browser to not to cache the response.

In ASP.NET (or ASP.NET MVC) you can do it like this:

Response.Headers.Add("Cache-Control", "no-cache");
DrJokepu
+1  A: 

you can change your settings in ie, but the problem most likely lies on your server. You can't go out and change all your users' browser settings. But if you want to at least check it on your browser, go to Internet Options->General (Tab)->Browsing History(section)->Settings (button)->"Every time I visit the webpage" Make sure you set it back, though, at some point.

To fix it on the server, have a look at http://www.mnot.net/cache%5Fdocs/

Using curl (w/ cygwin) for debugging is your great way to figure out what's actually being sent across the wire.

andersonbd1
+1  A: 

If cache-control doesn't work for you (see DrJokepu's answer), according to the spec the content from any URL with a query string should be non-cacheable, so you might append a pointless query parameter to your request URL. The value doesn't matter, but if you really want to be thorough you can append the epoch value, e.g.:

var url = "myrealurl?x=" + (new Date()).getTime();

But this is a hack; really this should be solved with proper caching headers at the server end.

T.J. Crowder
A: 

In the controller action that returns a JsonResult, you need to specify in your headers to avoid caching:

ControllerContext.HttpContext.Response.AddHeader("Cache-Control", "no-cache");
Kevin