【问题标题】:Failed to load resource: the server responded with a status of 404 () Controller.js:1加载资源失败:服务器响应状态为 404 () Controller.js:1
【发布时间】:2020-09-02 23:31:44
【问题描述】:

我正在使用 AngularJs 在 Visual Studio 中启动一个项目。出于某种原因,我在 Google 开发工具控制台中不断收到这篇文章标题中所述的错误。似乎找不到包含我的模块和控制器的 js 文件。如果我将模块和控制器放在 index.html 文件中的脚本标签中,它就可以正常工作。只有当我尝试将模块和控制器放在与 index.html 不同的文件中时,我才会遇到此问题。这是我所有文件的代码。

index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title></title>
</head>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="../Controller.js"></script>

<body ng-app="myApp" ng-controller="myCtrl">

    {{firstName}}

</body>

</html>

Controller.js

var app = angular.module("myApp", []);

app.controller("myCtrl", function ($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});

【问题讨论】:

    标签: javascript html asp.net angularjs


    【解决方案1】:

    通常 index.html 位于 Web 服务器目录的根目录中(我想这是您的情况)。服务器只知道服务器目录中的文件,或者至少限制对这些文件的访问。把你的Controller.js放在index.html的同一个目录或者index.html目录下的子目录下应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 2016-11-01
      • 2018-01-29
      • 2020-07-04
      • 1970-01-01
      • 2019-07-04
      • 2021-11-20
      • 2018-02-26
      相关资源
      最近更新 更多