【发布时间】:2012-06-21 14:16:43
【问题描述】:
首先,我想通过表达我对 IE 的厌恶程度来作为这个问题的序言。有时我会在半夜从 IE 引发的噩梦中醒来,让我尖叫着从床上跳起来,有时还会无情地殴打我周围的任何人。我的邻居讨厌它。只是听到“IE”让我畏缩。但我离题了。
无论如何,我的 MVC Web 应用程序上有一个页面,它通过 AJAX(通过不同的视图)启动一个新页面并显示一个图表。然而,问题是,当我打开新窗口时,仅在 IE 中,脚本没有加载(或者至少它们没有及时加载?)但是我在第一次引用时得到“jQuery 未定义” jQuery 对象。
但是,在重新加载时,一切正常。知道什么可能导致脚本无法在 IE 中加载吗? Chrome 和 FF 工作正常。
这是我用于新窗口的 ajax 调用:
$.ajax({
type: "POST",
url: actionURL + qs,
data: $(this).serialize(),
success: function (outputString) {
//$("#reportJSON").html(outputString).fadeIn();
var contentFromFirstPage = document.getElementById('reportArea').innerHTML;
var printContent = outputString;
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'scrollbars=1,menubar=1,height=800,width=600,resizable=1');
printWindow.document.write(printContent);
printWindow.focus();
//printWindow.document.close();
}
}).error(function (response) {
alert("something went wrong here with PrintPreview!!!" + response);
});
这里是 ajax 调用的操作:
public ActionResult PrintPreview(string reportId, string date, string dateFrom, string dateTo)
{
Reports reports = new Reports
{
ReportId = Convert.ToInt64(reportId),
Date = Convert.ToDateTime(date),
DateFrom = Convert.ToDateTime(dateFrom),
DateTo = Convert.ToDateTime(dateTo),
AvailableReports = this.FetchAvailableReports()
};
reports.AvailableReports = this.FetchAvailableReports();
reports.SelectedReport = this.FetchReportLayout(reports.ReportId);
reports.DynamicGridDataSource = this.FetchReportGrid(reports);
reports.DynamicChartDataSource = this.FetchReportChart(reports);
return renderViewToString("PrintPreview", reports);
}
【问题讨论】:
-
脚本是如何加载的?加载到新窗口的页面代码是什么样的?
-
像这样:
<script src="/RoadMap/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>我无法发布源代码,但代码没有任何异常。它根据上下文加载 Telerik 图表或网格 -
@Pointy 哦,新窗口通过不同的视图页面
-
几年前我曾经遇到过类似的问题,解决方案是我将 javascript 包含在页面底部(在新窗口中打开的页面)。希望同样适用于你
-
@RemarkLima 是的,是的,但无论如何这都无关紧要,因为
$().ready()中的$只是 jQuery 对象的别名,所以它会在该调用中失败不管
标签: c# javascript jquery asp.net internet-explorer