原文出處(詳細):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) {} }