最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - 0x800a1391 - JavaScript runtime error: 'jQuery' is undefined - Stack Overflow

programmeradmin0浏览0评论

I have a ASP .Net MVC4 Web application. In it I have my usual html for the _Layout.cshtml, which in turn loads the default 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:

.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. (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. 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. It was.

Now when I type in the url Home/ActionName the whole thing reloads as it should but looks horrible. and I get this error message:

0x800a1391 - JavaScript runtime error: 'jQuery' is undefined

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.

Again, when I load the page normally, it works fine. When I type Home on its own it works fine. Its only when I type Home/AnythingElse that it gives this error message. Even if I type Home/ which should load in the Index file, it gives me this error message.

jQuery is defined, so why is this happening on postback?

Any help is appreciated.

I have a ASP .Net MVC4 Web application. In it I have my usual html for the _Layout.cshtml, which in turn loads the default 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:

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. (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. 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. It was.

Now when I type in the url Home/ActionName the whole thing reloads as it should but looks horrible. and I get this error message:

0x800a1391 - JavaScript runtime error: 'jQuery' is undefined

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.

Again, when I load the page normally, it works fine. When I type Home on its own it works fine. Its only when I type Home/AnythingElse that it gives this error message. Even if I type Home/ which should load in the Index file, it gives me this error message.

jQuery is defined, so why is this happening on postback?

Any help is appreciated.

Share Improve this question asked Apr 11, 2013 at 12:26 Francis RodgersFrancis Rodgers 4,6858 gold badges48 silver badges65 bronze badges 4
  • 1 'not designed for MVC'? I think you need to go back to the ASP.Net tutorial pages. No offense, and yes i'm serious. I don't like ASP as much as the next person, but it's been MVC for a LOOOOOOOOONG time and from what I can see, you are already over-complicating tings. If they still have it, look for the tutorial on making an MVC music library. – SpYk3HH Commented Apr 11, 2013 at 12:30
  • 1 The jQuery file you're pointing to might not be there, only reason jQuery would be undefined – Mark Pieszak - Trilon.io Commented Apr 11, 2013 at 12:32
  • No offence taken, thanks for the answer. you missed where I said "out of the box" Its just client side stuff so of course with enough tweaking it will work with MVC. But I believe from the code on the site, that its all html4 / css2. Granted it works everywhere with enough code to support compatibility, but I did the music tutorial over a year ago so I am a little beyond it now (although still learning). Also, I do generally enjoy asp .net c# and other MS techs. Thanks. :) – Francis Rodgers Commented Apr 11, 2013 at 13:20
  • @mcpDESIGNS I did check the file exists there. hence the question. Its easier to check the existence of a file than to post a long descriptive question and reply to the answers. Anyway, if it didn't exist, it wouldn't work the first time it loads. But thanks for the suggestion. :) – Francis Rodgers Commented Apr 11, 2013 at 13:22
Add a comment  | 

3 Answers 3

Reset to default 9

Try setting the src for jQuery to be absolute from the site root:

<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/...

For me, the MVC bundlers were causing problems (in my case the 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

<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
发布评论

评论列表(0)

  1. 暂无评论