gpt4 book ai didi

c# - .NET Jquery 脚本错误

转载 作者:行者123 更新时间:2023-12-01 08:39:54 24 4
gpt4 key购买 nike

尝试执行 Jquery 函数,一切似乎都设置正常,但我在浏览器控制台日志中收到此错误

SCRIPT5009: 'jQuery' is not defined bootstrap.js (20,1)

HTML1300: Navigation occurred. 1 (1,1) 2 CSS3121: The media query -ms-viewport has been deprecated.

SCRIPT5009: SCRIPT5009: 'jQuery' is not defined bootstrap.js (21,1)

SCRIPT5009: SCRIPT5009: '$' is not defined SendEmail.js (1,1)

这是我的 View 脚本/样式:

@model Linkofy.Models.EmailAccount

@{
ViewBag.Title = "SendMail";
}
@section Styles {
<link href="@Url.Content("~/Styles/Edit.css")" rel="stylesheet" type="text/css" />
}
@section Scripts {
<script src="@Url.Content("~/Javascript/SendEmail.js")"></script>
}

我的函数(SendEmail.js):

$("#templateName").on("change", function () {

var tempID = $(this).find('option:selected').val();
var url = "/Identifiers/TemplateData/" + tempID;
console.log()

$.ajax({
type: "GET",
dataType: "json",
contentType: "application/json",
url: url, // Variabel
showLoader: true,
success: test // Function
});

});
function test(data) {
data = $.parseJSON(data);
$('#subject').val(data.subject);
$('#body').val(data.body);
}

捆绑:

    // 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.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"));
}
}
}

如果不填充此文件上的文本就无法发布,所以这是我的整个布局文件:

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

</head>
<body>
<div class="navbar" style="background-color: LightSteelBlue;">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Linkofy", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Domains", "Index", "Identifiers")</li>
<li>@Html.ActionLink("Clients", "Index", "Clients")</li>
<li>@Html.ActionLink("Links", "Index", "Links")</li>
<li>@Html.ActionLink("Status", "Index", "Status")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; @DateTime.Now.Year - Orb Online - Liam Cook</p>
</footer>
</div>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
@RenderSection("Styles", required: false)
</body>
</html>

enter image description here

enter image description here

最佳答案

该错误只能由以下三种情况之一引起:

  1. 您的 JavaScript 文件未正确加载到您的页面中

  2. 您的 jQuery 版本很糟糕。这可能会发生,因为有人编辑了核心文件,或者插件可能覆盖了 $ 变量。

  3. 在页面完全加载之前,您已经运行了 JavaScript,并且如下这样,在 jQuery 完全加载之前。

您应该检查 Firebug 网络面板以查看文件是否确实正确加载。如果没有,它将突出显示为红色,并在旁边显示“404”。如果文件加载正确,则意味着问题是第 2 号。

确保所有 jQuery javascript 代码都在代码块内运行,例如:

$(document).ready(function () {
//your code here
});

这将确保您的代码在 jQuery 初始化后加载。

最后要检查的一件事是确保在加载 jQuery 之前没有加载任何插件。插件扩展了“$”对象,因此如果您在加载 jQuery 核心之前加载插件,那么您将收到您所描述的错误。

注意:如果您正在加载不需要 jQuery 运行的代码,则无需将其放置在 jQuery 就绪处理程序中。该代码可以使用

分隔

document.readyState

确保标题标签脚本的布局应如下顺序:

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

关于c# - .NET Jquery 脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48748912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com