Json is being cached incorrectly

Thiago picture Thiago · May 24, 2011 · Viewed 7.4k times · Source

Hy!

My JS is requesting a JSON from controller to edit an existing object, a populated dropdownlist.

Then, the View send the actual values from my autosuggest dropdown, to lately the new value be compared to the old one and the new values be stored.

It is like a list of Persons. When I load the page, there is some persons in my ddl and I can add or delete persons.

This is my controller:

    [HttpGet]
    public JsonResult JSON(int order)
    {
        IEnumerable<Person> persons = dataServ.Envolvidos.GetPerson( order )
        return this.Json( new { Result = persons }, JsonRequestBehavior.AllowGet );
    }

And my Json call:

$.getJSON("/Order/JSON", { order: $("#Id").val() }, function (data) {
   ...
});

Everything is going fine, except by the point that I.E. is caching this JSON, and when I send the new values and come back to the edit the page again, the old values are there instead of the new. But the new values is stored on database, like should be.

I tested on Chrome and Firefox and after I edit and come to edit again, it's done a new json call and the new values are there, different from I.E.

Am I missing something? What I should do to JSON result don't be cached?

Answer

Milimetric picture Milimetric · May 24, 2011

This will disable caching for jQuery ajax:

jQuery.ajaxSetup({ cache: false });