Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

javascript - Unexpected token < in first line of 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>

The error says:

Uncaught SyntaxError: Unexpected token <    core.js: 1

It shows the error at <!doctype html> of the app.html.

core.js looks like this:

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);
            });
    };*/

});

It also gives me 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)

Besides, in console, when I click at core.js, it shows the contents of app.html and name it core.js.

Here is the snapshot:

Showing app.html instead of core.js

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.

I have tried adding/removing type="text/javascript" but no help with that either.

Also, status 200 is returned on get request for core.js.

Status: 200

What might be wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your page references a Javascript file at /Client/public/core.js.

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.

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!

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...