Philip Hendry's Blog

IE8 Caches jQuery Ajax results

Jan 6, 2010 • ASP.NET MVC, jQuery • Less than a minute read

In my client code I have a small chunk of javascript that fetches the data for my form asynchronously using Ajax :

$.getJSON(_config.getUrl, null, function(data) {
    _shiftPattern = data;

However, my server code was only being called on the first visit to the page and on subsequent attempts the browser seemed to be fetching cached results. Since my server side code is ASP.NET MVC the solution to this is very simple indeed and simply involves decorating the action method with a OutputCache attribute :

[OutputCache(Duration = 0, VaryByParam = "None")]
public ActionResult GetJson(int id)
    return Content(
        "application/json; charset=utf-8"

ASP.NET MVC is proving very elegant indeed :)

Post by: Philip Hendry