我在MVC 5中具有以下代码,无法弄清为什么在IE中运行时会出错。在chrome中可以正常工作。我已经阅读了有关jquery,bootstrap等顺序的文章,并尝试了这些修复程序,但它们无济于事。有谁知道为什么这行不通?
BundleConfig.cs
using System.Web;
using System.Web.Optimization;
namespace PaceArt_Document_Viewer
{
public class BundleConfig
{
// For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
更新 我已经尝试了所有修复程序,但似乎无济于事。调试器说它是在$($(document.ready ....)之前的第一个$。我已将脚本src标签内联调用jquery,validate和modinizr,但仍然收到相同的错误。
<script>
$(document).ready(function () {
@{
var folderPath = Request.Url.Segments.Last();
string url = HttpContext.Current.Request.Url.AbsoluteUri;
string urlSegment = url.Substring(folderPath.LastIndexOf('/') + 1);
string urlFilePath = url.Remove(urlSegment.Length - 4);
}
var filePath = "@folderPath";//02939e1a435e46169076a0f9c5960647 //3740da10833b4de481a3e558a7a69889";
var url = "@Url.Action("GetPDFInline", new { filePath = -1 })";
var result = url.replace(-1, $("#pdfDisplayPathInline1").val());
$("#pdfDisplay").attr('src', result)
$('.pdfLinks').on('click', function () {
var value = $(this).text();
var valueUpdate = value.slice(0, -4);
var path;
var filePathTrim = filePath.slice(0, -4);
if (filePathTrim == valueUpdate) {
path = filePathTrim + ".pdf";
} else {
path = filePathTrim + "\\" + valueUpdate + ".pdf";
}
var url = "@Url.Action("GetPDFAttachments", new { filePathlink = -1 })";
var result = url.replace(-1, path);
$("#pdfDisplay").attr('src', result)
});
});
</script>
答案 0 :(得分:-1)
由于捆绑包中的这一行,IE可能正在努力使用正确版本的jQuery-
"~/Scripts/jquery-{version}.js"
与其使用jQuery捆绑包,不如尝试使用脚本标签以及相应的jQuery版本(不是最小版本)
<script src="js/jquery-3.3.1.min.js"></script>
如果可行,则将您的捆绑软件修改为套件...