简体   繁体   English

JavaScript 路径未加载到 Live Server 扩展(VS 代码)

[英]JavaScript path doesn't load on Live Server extension (VS Code)

HTML and CSS files are working perfectly on my live server. HTML 和 CSS 文件在我的实时服务器上运行良好。 But every time I lead to a.js script it will not be shown on my live server.但是每次我引导到 a.js 脚本时,它都不会显示在我的实时服务器上。 If I try to load the.js file directly through the URL it shows "Cannot GET /line.js".如果我尝试通过 URL 直接加载 .js 文件,它会显示“Cannot GET /line.js”。 I already tried out everything I've found on the inte.net but it's still not working.我已经尝试了我在 inte.net 上找到的所有内容,但仍然无法正常工作。 Here are the points I checked/did:以下是我检查/执行的要点:

Installed Code Runner安装的代码运行器

Installed Node.js = node.js system path done安装 Node.js = node.js 系统路径完成

Settings = Live Server Config = specified browser Settings = Live Server Config = 指定浏览器

"liveServer.settings.CustomBrowser": "chrome" on JSON settings "liveServer.settings.CustomBrowser": "chrome" on JSON 设置

.js file is in a separate folder and accessed via <script src="line.js"></script> on index.html .js 文件位于单独的文件夹中,可通过 index.html 上的<script src="line.js"></script>访问

Chrome is set as default browser on my system Chrome 被设置为我系统上的默认浏览器

Thanks for your inputs.感谢您的投入。

If the js file is in a separate folder, you need to provide the exact route to the folder in the script tag, since in the current form it is trying to find the js file in the root directory.如果 js 文件位于单独的文件夹中,则需要在脚本标记中提供到该文件夹的确切路径,因为在当前表单中,它试图在根目录中查找 js 文件。 The script tag should look like this:脚本标签应如下所示:

<script src="FOLDER_NAME/line.js"></script>

It's possible that your javascript file is being loaded before the HTML page is rendered.有可能在呈现 HTML 页面之前加载了 javascript 文件。 You can try adding "defer" to your script tag like this:您可以尝试将“延迟”添加到您的脚本标签中,如下所示:

<script src="demo_defer.js" defer></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 html 文件中的 javascript 在我使用 VS Code 的实时服务器中工作正常,但如果我在本地打开 .html 文件,它就不起作用 - javascript in a html file works fine in my live server using VS Code but if i open the .html file locally it doesn't work VS Code 使用 Live Server Extension 将 Javascript 文件呈现为文本 - VS Code just renders Javascript file as Text using Live Server Extension Web 蓝牙:无法将 BLE 设备与具有 Live Server VS 代码扩展的移动设备配对 - Web Bluetooth: Can't pair BLE device with Mobile Device with Live Server VS Code extension VS Code 的实时服务器扩展不自动重新加载 - Live Server Extension for VS Code not Auto-Reloading VS Code Live Server 扩展添加/复制现有的 HTML 元素 - VS Code Live Server extension adding/duplicating existing HTML element 实时预览与代码扩展 - Live Preview Vs code Extension 我的 Visual Studio Live 服务器扩展不能正常运行 function - My visual studio live server extension doesn't function normally vscode 直播服务器扩展切断 JavaScript 代码 - vscode live server extension cuts off JavaScript code JavaScript代码无法加载页面 - Javascript code doesn't load the page html 和 javascript slider 在本地工作,但在实时服务器中不起作用 - html and javascript slider working locally but doesn't work in live server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM