【发布时间】:2015-10-10 08:09:42
【问题描述】:
我有一个 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
它在app.html 的<!doctype 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",但也没有任何帮助。
此外,core.js 的获取请求返回状态 200。
可能出了什么问题?
【问题讨论】:
-
core.js的内容是什么? -
问题不在HTML;它在 core.js 中。尝试获取最新版本(假设 core.js 是一个框架;否则,请检查您的代码)
-
core.js是否还包含类似“404 - 未找到文件”之类的内容? -
@Xufox:请看更新。
-
@AustinBrunkhorst:请检查更新。
标签: javascript html angularjs syntax-error uncaught-exception