意外的令牌<在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
它显示的错误<!doctype html> ;
app.html
。
核心。 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 <的请求时返回状态200 / code>。
Also, status 200 is returned on get request for core.js
.
可能出现什么问题?
推荐答案
您的页面引用了Javascript文件位于 /Client/public/core.js
。
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 / javascriptsrc =/ 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!
如果你找到一个名为 core.js
在 / Client / public /
,浏览器仍会生成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屋!