简体   繁体   English

Uncaught SyntaxError:使用本地主机时出现意外令牌

[英]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.

相关问题 未捕获到的SyntaxError:意外令牌。 使用ClassNotty时 - Uncaught SyntaxError: Unexpected token . when using ClassNotty 使用void()时未捕获的SyntaxError:意外的令牌) - Uncaught SyntaxError: Unexpected token ) when using void() 当没有“:”时,“未捕获的SyntaxError:意外令牌:”吗? - “Uncaught SyntaxError: Unexpected token :” when there is no “:”? 这个Uncaught SyntaxError有什么错误:意外的令牌&lt;在jquery中使用eval时? - what error is this Uncaught SyntaxError: Unexpected token < when using eval in jquery? Uncaught SyntaxError:与烧瓶一起使用传单时出现意外令牌 - Uncaught SyntaxError: Unexpected token when using leaflet with flask 未捕获的SyntaxError:使用谷歌图表时无效或意外的令牌 - Uncaught SyntaxError: Invalid or unexpected token when using google chart Uncaught SyntaxError:在Codeigniter中使用jQuery Ajax时出现意外令牌 - Uncaught SyntaxError: Unexpected token when using jQuery Ajax in Codeigniter 使用JSON.parse时,&#39;未捕获的SyntaxError:意外的标记u&#39; - 'Uncaught SyntaxError: Unexpected token u' when using JSON.parse Uncaught SyntaxError: Unexpected token &lt; 使用 bootstrap js 时 - Uncaught SyntaxError: Unexpected token < when using bootstrap js 在 TypeScript 中导入时出现“Uncaught SyntaxError: Unexpected token {” - "Uncaught SyntaxError: Unexpected token {" when importing in TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM