简体   繁体   中英

Failed to load resource: the server responded with a status of 404 () Controller.js:1

I am starting a project in Visual Studio using AngularJs. For some reason I keep getting the error stated in the title of this post in the Google dev tools console. It seems my js file that has my module and controller can't be found. If I put my module and controller inside script tags in my index.html file it works just fine. It's only when I try to have the module and controller in a separate file than my index.html that I get this issue. Here is my code for all files.

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";
});

Normally index.html is in the root of the web server directory (and I suppose it's your case). The server only knows about files in the server directory or at least restricts access to that files. Put your Controller.js in the same directory of index.html or in a subdirectory in the directory of index.html should solve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM