原文出处(详细):http://www.cnblogs.com/artech/archive/2013/01/03/cache-4-ie.html
解决方法1:通过为URL地址添加后缀的方式解决问题
<!DOCTYPE html> <html> <head> <script type="text/javascript"> $(function () { window.setInterval(function () { $.ajax({ url:'@Url.Action("GetCurrentTime")?'+ new Date().toTimeString() , success: function (result) { $("ul").append("<li>" + result + "</li>"); } }); }, 5000); }); </script> </head> </html>
解决方法2:通过jQuery的Ajax设置解决问题
<!DOCTYPE html> <html> <head> <script type="text/javascript"> $(function () { $.ajaxSetup({ cache: false }); window.setInterval(function () { $.ajax({ url:'@Url.Action("GetCurrentTime")', success: function (result) { $("ul").append("<li>" + result + "</li>"); } }); }, 5000); }); </script> </head> </html>
解决方法3:适用MVC 通过定制响应解决问题
public class HomeController : Controller { public ActionResult Index() { return View(); } [NoCache] public string GetCurrentTime() { return DateTime.Now.ToLongTimeString(); } } public class NoCacheAttribute : FilterAttribute, IActionFilter { public void OnActionExecuted(ActionExecutedContext filterContext) { filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); } public void OnActionExecuting(ActionExecutingContext filterContext) {} }