2016-05-13 60 views
0

內置MVC站點,其中包括jQuery的在這樣的佈局文件:

<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>@ViewBag.Title</title> 
    @Scripts.Render("~/bundles/jquery") 
    @Styles.Render("~/Content/css") 
</head> 
<body> 
    <!-- content --> 
</body> 
</html> 

jQuery是通過的NuGet引用和捆綁的是這樣的:

public class BundleConfig 
{ 
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
      "~/Scripts/jquery-{version}.js", 
      "~/Scripts/jquery-ui.min.js", 
      "~/Scripts/stickyfill.js")); 
} 

而且在Visual Studio中本地運行該站點時工作正常。

當我部署到IIS並嘗試運行該網站時,我得到了可怕的Uncaught ReferenceError: jQuery is not defined錯誤。

我檢查的第一件事是,jQuery的包通過該地址的部署頁嘗試使用可用:

/bundles/jquery?v=[a token] 

其所。您甚至可以在Chrome Developer工具的捆綁包中看到它。值得注意的是,通過相同機制使用令牌部署的css運行良好。

我也按照問題JQuery - $ is not defined的方式解決了問題,並將其清除或嘗試使用,但無濟於事。

我能想到的唯一的事情是它在jQuery(document).ready()的初始調用之前沒有加載 - 這就是爲什麼我將該包移動到<head>標記中的原因。但這並沒有幫助,我不知道我還能做些什麼來減慢或等待頁面加載。

這究竟是什麼?

編輯:Somone的要求呈現的頁面的頭:

<head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>[the title]</title> 
    <script src="/bundles/jquery?v=[a token]"></script> 
    <link href="/Content/css?v=[a token]" rel="stylesheet"/> 
</head> 
+0

你可以張貼'generated'頁的'HTML',至少頭部? – imvain2

+0

那麼網絡面板在加載jQuery文件時會說什麼? – epascarello

+0

@ imvain2完成 - 感謝您的期待 –

回答

1

試試這個:

public class BundleConfig 
{ 
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
      "~/Scripts/jquery-1.8.2.min.js", 
      "~/Scripts/jquery-ui.min.js", 
      "~/Scripts/stickyfill.js")); 
} 
+0

感謝您的建議,但它沒有幫助。 –

+0

我認爲你在頁面中使用jQuery兩次。 –

相關問題