0

Getting a: Error: ReferenceError: $ is not defined when I publish my website. Even though I have the JQuery lib added in the Layout page, and now also on the partialView that complains about not finding the JQuery lib This is how I reference it:

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

When I run the website locally, it works fine, no JS errors, but it is as soon as it is published, that it starts complaining. Normally I would add code with my question, but I am not really sure what code to add. I just want to know if there is a difference in how the js files are loaded when site is published, than when running locally. Has anyone experienced such errors?

On 2nd thoughts, I'll try add code anyway. The code that complains is this: (And it is in a partialview)

<script type="text/javascript">
    $(document).ready(function () {
        $('#slider').rhinoslider();

        $("#sliderHolderQitoz").toggle("fade", 6000);
    });    
</script>

My layout looks like this:

 <html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title</title>

    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>

    <link href="~/Content/rhinoslider-1.05.css" rel="stylesheet" />

    <link href="~/Scripts/jquery-ui.min.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-ui.min.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/OwnedScripts/InitializeUI.js"></script>
    <script src="~/Scripts/OwnedScripts/Dialogs.js"></script>
    <script src="~/Scripts/OwnedScripts/Misc.js"></script>

    <script src="~/Scripts/ExtraScripts/rhinoslider-1.05.min.js"></script>
    <script src="~/Scripts/ExtraScripts/rhinoslider-1.05.js"></script>
    <script src="~/Scripts/ExtraScripts/mousewheel.js"></script>
    <script src="~/Scripts/ExtraScripts/easing.js"></script>

Again, when running/debuggin locally, all is good, the error comes after publishing

user1960836
  • 1,732
  • 7
  • 27
  • 47

2 Answers2

1

Did you try to check the "real" path manually? On my opinion you have a different relative path local and on server.

Try to substitute with a standard HTML script check it localy and on the server.

Diego Martelli
  • 302
  • 1
  • 10
  • What do you mean exactly by: Try to substitute with a standard HTML script. I don't follow :) – user1960836 Apr 02 '15 at 01:47
  • 1
    You are right, I was a little criptic. You use "~" char in your plain html – Diego Martelli Apr 02 '15 at 07:34
1

I eventually found after spending an unrealistic amount of time, that the problem lies in the site not being able to locate the: _ViewStart.cshtml. This works fine when running locally, but when deploying the website it becomes a problem. And since all the script reference were place in the: _Layout.cshtml, I got the script error at page start. So the solution was to add the:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

at top of the Index page, then we all good.

It's funny how we programmers can end up using many hours on something that has such a simple solution. But the problem lies in find the actual cause/problem, to be able to apply the simple solution :D

user1960836
  • 1,732
  • 7
  • 27
  • 47