jQuery library location wants to be referenced differently on server

后端 未结 4 1216
再見小時候
再見小時候 2020-12-18 10:32

I\'ve got an ASP.NET MVC application that uses jQuery. To load the js libraries, I reference them like this:



        
相关标签:
4条回答
  • 2020-12-18 10:48

    As Andrew says, your directory structure is totaly different. Have you considered using google's load library to load Jquery for you from the closet location to the user?

    0 讨论(0)
  • 2020-12-18 10:58

    The reason your code is working locally is because your local directory structure is different from your production directory structure.

    That being said I believe that an absolute path to any external resources (javascript, images, and stylesheets) is best.

    0 讨论(0)
  • 2020-12-18 11:05

    Try this:

    <script type="text/javascript" src='<%= Url.Content("~/Scripts/jquery-1.3.2.min.js") %>'></script>
    

    This will relativize the path to the root of your application regardless of whether it is at the top level or in a virtual directory. I actually developed a HtmlHelper extension that lets clean this up to:

    <%= Html.Javascript( Url.Content( "~/Scripts/jquery-1.3.2.min.js" )) %>
    

    Add the following to get intellisense. This needs the relative path to work, but gets excluded at runtime because the condition (always) fails.

    <% if (false) { %>
         <script type="text/javascript" src="../../Scripts/jquery-1.3.2.vsdoc.js"></script>
    <% } %>
    
    0 讨论(0)
  • 2020-12-18 11:08

    Have you tried referencing the file from the root url? I.e. instead of "../../", which has to crawl up a directoy, use "/Content/Scripts/jquery-1.3.2.min.js". This would angnostic of your directory structure.

    You should also consider using google to load jquery:

    http://code.google.com/apis/ajaxlibs/

    You'll get much better load times.

    Mike

    0 讨论(0)
提交回复
热议问题