![](/img/trans.png)
[英]Javascript, Jquery works fine in localhost but not in the deployed site?
[英]JQuery - works locally but $ is not defined but only on deployed site
在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的問題-$未定義 ,沒有刪除或嘗試過$都無濟於事。
我唯一能想到的是它在首次調用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>
嘗試這個 :
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"));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.