Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
75
rated 0 times [  82] [ 7]  / answers: 1 / hits: 16570  / 11 Years ago, tue, september 24, 2013, 12:00:00

My project is in MVC 4. My scripts are in _Layout.cshtml when reload the page the following error: JScript runtime error: '$' is undefined



_Layout.cshtml:



 <head>
<meta charset=utf-8 />
<title>@ViewBag.Title</title>
<link href=~/Images/favicon.ico rel=shortcut icon type=image/x-icon />
<meta name=viewport content=width=device-width />
@Styles.Render(~/Content/css)
@Scripts.Render(~/bundles/modernizr)
@Scripts.Render(~/bundles/jquery)
@Scripts.Render(~/bundles/jqueryui)
<script type=text/javascript src=~/Scripts/jquery.qtip-1.0.0-rc3.min.js> </script>
</head>


My Partial View:



   <script type=text/javascript>

$('#lnkOrganizar').click(function () {
if (($('.frozenTopC').css('display') != 'none') && ($('.frozenTopConteudo').css('display') != 'none')) {
$('.frozenTopC').css('display', 'none');
$('.frozenTopConteudo').css('display', 'none');
}
else {
$('.frozenTopC').css('display', 'table-cell');
$('.frozenTopConteudo').css('display', 'table-cell')
}
});

</script>

More From » jquery

 Answers
78

jquery isn't present.



Look at this line: <script type=text/javascript src=~/Scripts/jquery.qtip-1.0.0-rc3.min.js> </script>



Check that you have that Scripts/jquery.qtip-1.0.0-rc3.min.js on the server



It is also NOT usual to refer to your home directory there - where you have the ~. If your script is in a Scripts directory then you just use Scripts/jquery.qtip-1.0.0-rc3.min.js because with a web server, everything is within it's root (top level) directory.



Also is this file the main jquery library? It's not clear to me whether this is just your script code and if so you'll need to include the main js library with something like:



<script src=//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js></script>


btw, aim to use lowercase for directory names - scripts not Scripts as it will make your life easier in the long run. I would also recommend script not scripts as many directories have multiple files (their purpose after all) so most folks use singular directory. This is closer to a preference though than the ~ issue.



Also, while debugging and playing around, remember that you can actually have the script in the same file, within <script> tags, not in a separate file. Not recommended long-term as a good practice but useful for seeing where the issue is.


[#75468] Monday, September 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennie

Total Points: 593
Total Questions: 102
Total Answers: 106

Location: Federated States of Micronesia
Member since Fri, Sep 16, 2022
2 Years ago
jennie questions
;