ajax request that returns json array, IE6/7 is caching it and data is not fresh

天大地大妈咪最大 提交于 2019-12-25 02:47:35

问题


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:


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



回答2:


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_docs/

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




回答3:


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.




回答4:


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


来源:https://stackoverflow.com/questions/1294155/ajax-request-that-returns-json-array-ie6-7-is-caching-it-and-data-is-not-fresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!