[英]Uncaught SyntaxError: Unexpected token when using localhost
I am new to javascript, need help. 我是javascript新手,需要帮助。 I have created a index.html and a app.js (both in same path), and have hosted the index.html as localhost.
我创建了一个index.html和一个app.js(都在同一路径中),并将index.html作为本地主机托管。
When I run individual index.html I do get the hello alert, but when I run using localhost I get "Uncaught SyntaxError: Unexpected token <" error. 当我运行各个index.html时,会收到hello警报,但是当我使用localhost运行时,会出现“ Uncaught SyntaxError:Unexpected token <”错误。
Below is the code that i used: 以下是我使用的代码:
Index.html: Index.html:
<!DOCTYPE HTML>
<html>
<head>
<title>Show Javascript alert</title>
<script type="text/javascript" src="app.js"></script>
</head>
<body>
</body>
</html>
app.js: app.js:
function display_alert(){
alert("Hello!");
}
window.onload = display_alert;
I think the Webserver is not serving your app.js File. 我认为网络服务器未提供您的app.js文件。 Have you tried to open it in your Browser, to check if the Path is right?(eg http://localhost/app.js ).
您是否尝试在浏览器中打开它,以检查路径是否正确?(例如, http://localhost/app.js )。
Check if the Name of the File is Lowercase as well and if the Webserver has read Permissions on the File. 检查文件名是否也为小写,并且Web服务器是否已读取文件上的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.