admin管理员组

文章数量:1353186

I get the exception - "JavaScript runtime error: Object doesn't support property or method 'jqGrid'" when I move below block from maincontent of content page to header section of master page.

<link href="../Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<link href="../Content/jquery.jqGrid/jquery-ui-custom.css" rel="stylesheet" />
<script src="../Scripts/jquery-1.9.1.min.js"></script>
<script src="../Scripts/jquery.jqGrid.js"></script>
<script src="../Scripts/i18n/grid.locale-en.js"></script>


It only works when I place this block in trailing section of master page.
Could someone help me understand why it works only when I place this block in trailing section of master page but not in header section? I think this has something to do with loading dependencies and initialization of jqGrid, however I need concrete understanding.

I get the exception - "JavaScript runtime error: Object doesn't support property or method 'jqGrid'" when I move below block from maincontent of content page to header section of master page.

<link href="../Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<link href="../Content/jquery.jqGrid/jquery-ui-custom.css" rel="stylesheet" />
<script src="../Scripts/jquery-1.9.1.min.js"></script>
<script src="../Scripts/jquery.jqGrid.js"></script>
<script src="../Scripts/i18n/grid.locale-en.js"></script>


It only works when I place this block in trailing section of master page.
Could someone help me understand why it works only when I place this block in trailing section of master page but not in header section? I think this has something to do with loading dependencies and initialization of jqGrid, however I need concrete understanding.

Share Improve this question edited Mar 17, 2014 at 6:13 SuicideSheep 5,55020 gold badges69 silver badges123 bronze badges asked Mar 17, 2014 at 6:08 AbSharpAbSharp 1192 gold badges6 silver badges20 bronze badges 2
  • Is your jqGrid call within jQuerys document.ready function? api.jquery./ready – Chase Commented Mar 17, 2014 at 6:10
  • where is trailing section of master page? – Ashwini Verma Commented Mar 17, 2014 at 6:11
Add a ment  | 

1 Answer 1

Reset to default 5

You have to wait until DOM finishes loading. Then you can apply your scripts. Since, in your master page, you are using the script at the bottom, since the parser uses top down approach, it executes the script, after the body is pleted loading.

So, if you do want to put in head section, ensure that all your script is inside document.ready() function

Also , know that it is always a best practice to put all your scripts at bottom rather than at the header.

This is a good performance indicator. Also it avoids the usage of ready function

Hope this helps..

本文标签: aspnetJavaScript runtime error Object doesn39t support property or method 39jqGrid39Stack Overflow