意外的令牌 <在 HTML 的第一行 [英] Unexpected token < in first line of HTML
问题描述
我有一个 HTML 文件:
I have an HTML file :
<!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
它显示了 的
app.html
处的错误.
It shows the error at <!doctype html>
of the 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);
});
};*/
});
它还给了我 未捕获的错误:[$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
>.
Besides, in console, when I click at core.js
, it shows the contents of app.html
and name it core.js
.
截图如下:
此外,如图所示,当我单击 index.html
时,它会显示 app.html
.但是,我没有任何名为 index.html
的文件,我默认加载 app.html
而不是 index.html
.
Also, as in the image, when I click index.html
, it shows app.html
. However, I do not have any file that is named index.html
and I load app.html
by default instead of index.html
.
我尝试添加/删除 type="text/javascript"
但也没有帮助.
I have tried adding/removing type="text/javascript"
but no help with that either.
此外,对 core.js
的 get 请求返回状态 200.
Also, status 200 is returned on get request for core.js
.
可能有什么问题?
推荐答案
您的页面引用了位于 /Client/public/core.js
的 Javascript 文件.
Your page references a Javascript file at /Client/public/core.js
.
可能找不到此文件,而是生成网站的首页或 HTML 错误页面.这是一个很常见的问题,例如.在 Apache 服务器上运行的网站,其中路径默认重定向到 index.php
.
This file probably can't be found, producing either the website's frontpage or an HTML error page instead. This is a pretty common issue for eg. websites running on an Apache server where paths are redirected by default to index.php
.
如果是这种情况,请确保替换脚本标签中的 /Client/public/core.js
<script type="text/javascript" src="/Client/public/core.js"></script>
使用正确的文件路径或将丢失的文件 core.js
放在位置 /Client/public/
> 修复您的错误!
If that's the case, make sure you replace /Client/public/core.js
in your script tag <script type="text/javascript" src="/Client/public/core.js"></script>
with the correct file path or put the missing file core.js
at location /Client/public/
to fix your error!
如果您已经在 /Client/public/
找到了一个名为 core.js
的文件并且浏览器仍然生成一个 HTML 页面,请检查文件夹和文件.其中任何一个都可能缺乏适当的权限.
If you do already find a file named core.js
at /Client/public/
and the browser still produces a HTML page instead, check the permissions for folder and file. Either of these might be lacking the proper permissions.
这篇关于意外的令牌 <在 HTML 的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!