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?
If the JSON file is being read and used by PHP on the server then it won't (can't!) be cached by the user's browser. The resulting pages might be cached, though, either by the browser or by some intervening proxy, or both.
Request Headers 2nd request: Thx for response. Yes you can cache JSON responses.
By default, Cloudflare does not cache JSON files without being forced by a Page Rule.
This will disable caching for jQuery ajax:
jQuery.ajaxSetup({ cache: false });
I believe IE caches JSON requests by default, unlike the other browsers. You will have to manually include the appropriate headers to tell the response not to be cached. This won't hurt the existing browsers which already don't cache, it will just be more explicit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With