我使用下面的代碼使用jQuery重新加載圖像:使用控制器IE下未能更改圖像的src一旦SRC已經定義一旦
//Fetch image associated with new image imap.
var reportID = parseInt($('#ReportSelector').val());
$('#HistoricalChart').bind('load', function() {
alert("loaded");
$(this).unbind('load');
$('#ChartLoading').hide();
$(this).show();
}).bind('error', function() {
$(this).unbind('error');
$('#ChartLoading').hide();
$('#ChartLoadingError').show();
}).attr('src', '../Chart/HistoricalChart?ReportID=' + reportID);
這個jQuery鏈的最後一行表示我希望改變HistoricalChart的src屬性。我使用以下控制器操作來執行此操作:
public ActionResult HistoricalChart(int reportID)
{
LineChart lineChart = (LineChart)Session[string.Format("HistoricalReport: {0}", reportID)];
MemoryStream memoryStream = lineChart.ConvertToMemoryStream();
return File(memoryStream, "image/png");
}
這可以在Chrome下正常工作。然而,在IE9下,這只是第一次。每次在IE下都會觸發「加載」警報 - 只有圖像不會更改。
也就是說,我有一個斷點HistoricalChart方法的內部設置。 HistoricalChart img第一次設置了src - 斷點被擊中。然而,在這之後,調用.attr('src',...)後斷點不會被擊中。
理想的情況下我也不會清除src屬性,或隱藏圖像,來解決這個問題。與其交互時,我不希望圖像閃爍。
這是IE的一個已知限制嗎?解決方法?或者我在做一些不正確的事情?
它是一個緩存的問題?嘗試在您的網址中添加緩存攔截器。 '../Chart/HistoricalChart?ReportID='+ reportID +'&cachebuster ='+ new Date()。getTime()' – 2012-02-13 18:23:37