【问题标题】:java script file 404 (Not Found)javascript文件404(未找到)
【发布时间】:2016-09-09 11:19:23
【问题描述】:

来自 MVC 应用程序的我的 index.html 文件包含以下代码。所有文件都加载到浏览器中,但没有加载 Views 文件夹中的文件。 Index.html 文件、脚本和视图文件夹位于根位置。

   <body>
   <div ng-view></div>

        <script src="Scripts/jquery-1.9.1.min.js"></script>
        <script src="Scripts/angular.min.js"></script>
        <script src="Scripts/angular-route.min.js"></script>
        <script src="Scripts/app.js"></script>
        <script src="Views/Authentication/Services.js"></script> -- Error here
        <script src="Views/Authentication/AuthenticationController.js"></script> -- Error here

    </body>

文件夹结构

当我从 chrome devtool 检查时收到以下错误消息。

http://localhost:58348/Views/Authentication/AuthenticationController.js404(未找到)

即使我在 web.config 中添加了 js/html 处理程序,但仍然面临同样的问题。

 <add name="JavaScriptHandler" path="*.js" verb="*" preCondition="integratedMode"
            type="System.Web.StaticFileHandler" />

          <add name="HtmlScriptHandler" path="*.html" verb="*" preCondition="integratedMode"
               type="System.Web.StaticFileHandler" />

【问题讨论】:

  • 我认为是路径的问题。 Scripts/Vies... 也许?
  • 您的脚本在 Views 文件夹还是 Scripts 文件夹中?
  • Index.html 文件,Scripts & Views 文件夹位于根目录。

标签: javascript asp.net-mvc


【解决方案1】:

由于路径不正确,视图可能无法访问脚本文件。

试试,

<script src="~/Views/Authentication/AuthenticationController.js"></script>

【讨论】:

    【解决方案2】:

    我在下面的帖子中进行了裁判,通过将 web.config(带有 js/html 处理程序)添加到视图文件夹中解决了我的问题。

    Where to put view-specific javascript files in an ASP.NET MVC application?

    【讨论】:

      【解决方案3】:

      首先,判断Scripts/jquery-1.9.1.min.js文件是否在WEB-INF下 如果在此文件中,则切换到其同级目录, 这可能会有所帮助

      【讨论】:

        猜你喜欢
        • 2018-02-04
        • 2020-12-30
        • 2015-02-27
        • 2022-11-06
        • 2016-09-12
        • 2020-06-10
        • 2017-04-01
        • 2020-11-03
        • 2014-11-10
        相关资源
        最近更新 更多