尽管设置了"No Store",但iPad缓存了AJAX响应

Ian*_*ger 4 javascript asp.net safari ajax ipad

我有一个页面,它执行AJAX请求以获取数据,然后由用户进行修改.使用iPad时,如果用户进行了更改,然后离开页面,然后返回 - AJAX请求不会重新运行 - 这意味着旧数据被加载(可能来自iPad的浏览器缓存).

我的服务器代码是ASP.NET Forms,我尝试使用我能找到的所有设置设置无缓存:

Context.Response.Cache.SetNoStore()
Context.Response.Cache.SetETag(New Guid().ToString())
Context.Response.Cache.SetExpires(New DateTime())
Context.Response.Cache.SetNoServerCaching()
Context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
Context.Response.Expires = 0
Run Code Online (Sandbox Code Playgroud)

但没有运气.有任何想法吗?

cbu*_*mer 5

正如前面的答案所提出的,jQuery 为它的$ .ajax方法提供了一个简单的选项缓存:

如果设置为false,它将强制浏览器不缓存请求的页面.将cache设置为false还会将查询字符串参数"_ = [TIMESTAMP]"附加到URL.

例如:

$.ajax({
  url: "test.html",
  cache: false,
  success: function () {
    $(this).addClass("done");
  }
});
Run Code Online (Sandbox Code Playgroud)

如果您不使用jQuery,您可以自己实现类似的行为.