我在我的一个ASP MVC视图上使用fancybox插件通过Ajax调用显示错误消息。但是,它似乎正在缓存结果。下面是我用来从表中检索错误的Linq查询
public JsonResult GetErrors(string term)
{
try
{
int id = int.Parse(term);
var errors = (from e in db.TransmissionHistory
where (e.TransmissionTable == TABLE) &&
(e.TranTableId == id) &&
(e.ReplyResult == RESULT)
orderby e.TransmittedOn descending
select e).FirstOrDefault();
if (errors == null)
{
return Json("Search returned no results", JsonRequestBehavior.AllowGet);
}
List<string> errs = new List<string>();
errs = errors.Errors.Split(',').ToList();
return Json(errs, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
return Json("There was an error processing your request, please try again", JsonRequestBehavior.AllowGet);
}
}
如果我在第一行设置断点:int id = int.Parse(term);
这段代码只会在我第一次点击启动fancybox / Ajax调用的图片时执行。因此,这最终成为fancybox模式中显示的唯一信息。
linq
查询应该获取最新的错误消息(由日期字段确定),但是如果在启动fancybox / ajax调用后出现新的错误消息,您将看不到它。而是再次简单地显示先前查询的结果。此外,重申一下,在这种情况下(第二次启动呼叫)断点不会触发。
我对这个插件不太熟悉,所以我认为这意味着我以某种方式缓存了调用的结果。但是,我在网上详细介绍了fancybox的缓存属性和/或如何更改它们。为了更好的衡量,这里是fancybox jquery:
$('.checkErrors').click(function () {
var $tr = $(this).closest('tr');
var firstName = $tr.find('td:nth-child(2)').text();
var lastName = $tr.find('td:nth-child(3)').text();
$.ajax({
type: 'GET',
url: '@Url.Action("GetErrors","AgentTransmission")',
data: { term: $(this).attr('id') },
dataType: 'json',
success: function (data) {
var display = "<center><h2>" + firstName + " " + lastName + "</h2></center><ul>";
if (data == "Search returned no results" || data == "There was an error processing your request, please try again") {
display += "<li>" + data + "</li>";
} else {
$.each(data, function (key, value) {
display += "<li>" + value + "</li>";
});
}
display += "</ul>";
$.fancybox(display, {
// fancybox API options
fitToView: false,
autoScale: true,
autoDimension: true,
closeClick: true,
openEffect: 'fade',
closeEffect: 'fade',
closeBtn: true,
openSpeed: 'fast',
closeSpeed: 'fast'
});
},
error: function (data) {
$.fancybox("There was an error processing your request. We apologize for the inconvenience!", {
// fancybox API options
fitToView: false,
autoScale: true,
autoDimension: true,
closeClick: true,
openEffect: 'fade',
closeEffect: 'fade',
closeBtn: true,
openSpeed: 'fast',
closeSpeed: 'fast'
});
}
});
});
答案 0 :(得分:1)
这是因为没有在Ajax调用上设置缓存属性,而不是fancybox。只需将cache: false
添加到ajax调用即可解决问题。