我有一个 HTML 文件:
<!DOCTYPE HTML>
<html lang="en-US" ng-app="Todo">
<head>
<meta charset="UTF-8">
<title>DemoAPI</title>
<meta name="viewport">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<link rel="stylesheet" href="./Client/css/styling.css" />
<script type="text/javascript" src="core.js"></script>
</head>
错误说:
Uncaught SyntaxError: Unexpected token < core.js: 1
它显示错误在 <!doctype html>
的 app.html
.
core.js
看起来像这样:
angular.module('Todo', [])
.controller('mainController', function($scope, $http)
{
$scope.formData = {};
// get all and show them
$http.get('/musicians')
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
//get with an id
$scope.getOneTodo = function() {
$http.get('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
// send the text to the node API
$scope.createTodo = function() {
$http.post('/musicians', $scope.formData)
.success(function(data) {
$scope.formData = {}; // clear the form
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
})
};
// delete
$scope.deleteTodo = function(id) {
$http.delete('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
/*
$scope.updateTodo = function(id) {
$http.delete('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};*/
});
它还给我 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=Todo&p1=Error%3A%2…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381)
此外,在控制台中,当我单击 core.js
时, 它显示了 app.html
的内容并将其命名为core.js
.
这是截图:
此外,如图所示,当我单击 index.html
时, 它显示 app.html
.但是,我没有任何名为 index.html
的文件然后我加载 app.html
默认情况下而不是 index.html
.
我尝试添加/删除 type="text/javascript"
但也没有帮助。
此外,状态 200 在 core.js
的获取请求中返回.
可能出了什么问题?
最佳答案
您的页面在 /Client/public/core.js
引用了一个 Javascript 文件.
可能无法找到该文件,而是生成网站首页或 HTML 错误页面。对于例如,这是一个非常普遍的问题。在 Apache 服务器上运行的网站,其中路径默认重定向到 index.php
.
如果是这种情况,请确保替换 /Client/public/core.js
在你的脚本标签中 <script type="text/javascript" src="/Client/public/core.js"></script>
使用正确的文件路径或放置丢失的文件 core.js
在位置/Client/public/
修复您的错误!
如果您已经找到名为 core.js
的文件在/Client/public/
并且浏览器仍然生成 HTML 页面,请检查文件夹和文件的权限。其中任何一个都可能缺少适当的权限。
关于javascript - 意外标记 < 在 HTML 的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31529446/