Json 缓存不正确
嘿!
我的 JS 正在从控制器请求 JSON 来编辑现有对象(填充的下拉列表)。
然后,视图从我的自动建议下拉列表中发送实际值,最近将新值与旧值进行比较并存储新值。
它就像一个人员列表。当我加载页面时,我的 ddl 中有一些人,我可以添加或删除人。
这是我的控制器:
[HttpGet]
public JsonResult JSON(int order)
{
IEnumerable<Person> persons = dataServ.Envolvidos.GetPerson( order )
return this.Json( new { Result = persons }, JsonRequestBehavior.AllowGet );
}
我的 Json 调用:
$.getJSON("/Order/JSON", { order: $("#Id").val() }, function (data) {
...
});
一切都很顺利,除了 IE 缓存这个 JSON 之外,当我发送新值并再次返回编辑页面时,旧值就在那里,而不是新的。但新值应该存储在数据库中。
我在 Chrome 和 Firefox 上进行了测试,在我编辑并再次编辑后,它完成了一个新的 json 调用,并且新值在那里,与 IE 不同,
我是否遗漏了一些东西?我应该如何处理 JSON 结果不被缓存?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将禁用 jQuery ajax 的缓存:
This will disable caching for jQuery ajax:
我相信 IE 默认情况下会缓存 JSON 请求,这与其他浏览器不同。您必须手动包含适当的标头以告诉响应不被缓存。这不会损害已经不缓存的现有浏览器,它只会更加明确。
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.