简体   繁体   English

0x800a1391 - JavaScript运行时错误:'jQuery'未定义

[英]0x800a1391 - JavaScript runtime error: 'jQuery' is undefined

I have a ASP .Net MVC4 Web application. 我有一个ASP .Net MVC4 Web应用程序。 In it I have my usual html for the _Layout.cshtml, which in turn loads the default Home/Index. 在其中我有_Layout.cshtml的常用html,后者又加载默认的Home / Index。 All works fine. 一切正常。

In my index I am also loading a partial view. 在我的索引中,我也加载了局部视图。 This works fine too. 这也很好。 No probs. 没有问题。

I am using a the UI tools from the following site: 我正在使用以下网站的UI工具:

http://www.keenthemes.com/preview/index.php?theme=metronic http://www.keenthemes.com/preview/index.php?theme=metronic

The problem is it seems to be primarily HTML4 and not designed for MVC out of the box so I am having to tweak it slightly to get it to work the way I want. 问题是它似乎主要是HTML4而不是为开箱即用的MVC设计的,所以我不得不稍微调整它以使它按照我想要的方式工作。 (Nothing beyond anything very basic). (没有任何超越任何基本的东西)。 For example, moving one part out to the index and using Renderbody() to load it so the actual html structure never changes. 例如,将一个部分移动到索引并使用Renderbody()加载它,以便实际的html结构永远不会改变。 I have done this a million times to be sure I am not missing any closing tags or anything else that could cause my problem. 我做了一百万次,以确保我没有遗漏任何结束标签或任何其他可能导致我的问题。

Up to this point there is no problem at all. 到目前为止,根本没有问题。 Everything loads as it should. 一切都按照应有的方式加载。

I continued to create a 2nd View and its partial to extract other parts of the site. 我继续创建第二个视图,它的部分提取网站的其他部分。 As usual, baby steps first. 像往常一样,宝贝先迈出一步。 Before extracting any other code, I just used a little "Hello World" in the first page, and a similar string in the partial to be sure it was working. 在提取任何其他代码之前,我只是在第一页中使用了一个“Hello World”,并在partial中使用了类似的字符串以确保它正常工作。 It was. 它是。

Now when I type in the url Home/ActionName the whole thing reloads as it should but looks horrible. 现在,当我输入url Home / ActionName时,整个事情会重新加载,但看起来很糟糕。 and I get this error message: 我收到此错误消息:

0x800a1391 - JavaScript runtime error: 'jQuery' is undefined 0x800a1391 - JavaScript运行时错误:'jQuery'未定义

Below is my code which clearly defines it: 以下是我的代码,它清楚地定义了它:

<!-- BEGIN CORE PLUGINS -->
<script src="assets/plugins/jquery-1.8.3.min.js" type="text/javascript"></script>
<script>
    jQuery(document).ready(function ()
    {
        App.init(); // initlayout and core plugins
        _Layout.init();
        _Layout.initJQVMAP(); // init index page's custom scripts
        _Layout.initCalendar(); // init index page's custom scripts
        _Layout.initCharts(); // init index page's custom scripts
        _Layout.initChat();
        _Layout.initDashboardDaterange(); //Red date range
        _Layout.initIntro(); //Pop up messages
    });
</script>

It points me to the jQuery(document).ready part when I see the message. 当我看到消息时,它指向jQuery(document).ready部分。

Again, when I load the page normally, it works fine. 再次,当我正常加载页面时,它工作正常。 When I type Home on its own it works fine. 当我自己键入Home时,它工作正常。 Its only when I type Home/AnythingElse that it gives this error message. 它只有当我键入Home / AnythingElse时它才会出现此错误消息。 Even if I type Home/ which should load in the Index file, it gives me this error message. 即使我键入Home /应该在Index文件中加载,它也会给我这个错误信息。

jQuery is defined, so why is this happening on postback? 定义了jQuery,为什么会在回发时发生这种情况?

Any help is appreciated. 任何帮助表示赞赏。

Try setting the src for jQuery to be absolute from the site root: 尝试将jQuery的src设置为站点根目录的绝对值:

<script src="/assets/plugins/jquery-1.8.3.min.js" type="text/javascript"></script>

Note the / before assets - when your src path does not start with a / the browser will try and load the asset relative to the current path, so in your example when you add the trailing slash to Home it will try to load jQuery from Home/assets/plugins/... 注意/之前的assets - 当你的src路径没有以/开头时,浏览器将尝试相对于当前路径加载资产,因此在你的示例中,当你将尾部斜杠添加到Home ,它将尝试从Home/assets/plugins/...加载jQuery Home/assets/plugins/...

For me, the MVC bundlers were causing problems (in my case the ui bundler) 对我来说,MVC捆绑包引起了问题 (在我的情况下是ui bundler)

Here is the order which worked for me. 这是对我有用的订单。

    <script src="/Scripts/modernizr-2.5.3.js"></script>
    <script src="/Scripts/jquery-1.7.1.js"></script>
    <script src="/bundles/jquery-ui"></script>
    <script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
    <script src="/Scripts/jquery.validate.js"></script>
    <script src="/Scripts/jquery.validate.unobtrusive.js"></script>

You need to add the jquery-x.xx.x.js first before the validate.js like this 您需要首先在validate.js之前添加jquery-x.xx.x.js

<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ 0x800a1391-JavaScript运行时错误:&#39;jQuery&#39;未定义”错误 - “0x800a1391 - JavaScript runtime error: 'jQuery' is undefined” Error 0x800a1391-JavaScript运行时错误:&#39;bobj&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'bobj' is undefined 0x800a1391-JavaScript运行时错误:&#39;PageMethods&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'PageMethods' is undefined 0x800a1391-JavaScript运行时错误:&#39;jQuery&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'jQuery' is undefinedd 创建一个MVC4项目-0 0x800a1391-JavaScript运行时错误:“ jQuery”未定义”错误 - Create an MVC4 project -0 0x800a1391 - JavaScript runtime error: 'jQuery' is undefined” Error 在母版页正文加载时调用jQuery函数:0x800a1391-JavaScript运行时错误:函数未定义 - Calling jQuery function on Master Page body onload: 0x800a1391 - JavaScript runtime error: function is undefined IE 10引发“ 0x800a1391-JavaScript运行时错误:&#39;jQuery&#39;未定义”(ASP.NET) - IE 10 Throws “0x800a1391 - JavaScript runtime error: 'jQuery' is undefined” (ASP.NET) 0x800a1391-JavaScript运行时错误:Visual Studio Enterprise 2015中未定义&#39;bobj&#39; - 0x800a1391 - JavaScript runtime error: 'bobj' is undefined in Visual Studio Enterprise 2015 异常0x800a1391-JavaScript运行时错误:在ASP.NET MVC中未定义&#39;JSON&#39; - Exception 0x800a1391 - JavaScript runtime error: 'JSON' is undefined in asp.net mvc 0x800a1391-JavaScript运行时错误:“ Edit_Button_Click”未定义 - 0x800a1391 - JavaScript runtime error: 'Edit_Button_Click' is undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM