【发布时间】:2016-11-20 07:26:07
【问题描述】:
我已经编写了一些代码,我使用node.js 从我的节点服务器提供服务。我的 HTML 服务很好,但是当我开始向 index.html 文件添加脚本时,我发现开发人员控制台中出现了最奇怪的错误:
Uncaught SyntaxError: Unexpected token < jquery-1.12.4.min.js:1
Uncaught SyntaxError: Unexpected token < hack.js:1
这是我的 HTML:
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="hack.css">
</head>
<body>
<h1>Colour Hack v1.0</h1>
<p>Guess the correct values for each colour to unlock information on the European Union.</p>
<script src="jquery-1.12.4.min.js"></script>
<script src="hack.js"></script>
</body>
</html>
hack.js 代码:
const box = "<canvas>BOX</canvas>"
$(document).ready(function() {
$("p").append(box);
});
而节点服务器(server.js)代码为:
//Import http and file server libraries
const http = require('http');
const fs = require('fs');
//Define port for comms
const PORT = 8080;
//Start server
http.createServer(function(request, response) {
response.writeHead(200);
fs.readFile('index.html', function(err, contents) {
response.write(contents);
response.end;
});
}).listen(PORT);
console.log('Server listening on port: %s', PORT);
为什么会出现关于意外尖括号的错误??
【问题讨论】:
标签: jquery html node.js server runtime-error