0
我在我的一個ASP MVC視圖中使用fancybox插件來通過Ajax調用顯示錯誤消息。但是,它似乎在緩存結果。下面是我用它來從表中檢索錯誤LINQ查詢Fancybox插件似乎緩存結果
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的PIC/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'
});
}
});
});
即將這樣說。我想你可以接受你自己的答案並結案。 – JFK