简体   繁体   中英

trouble with relative path to javascript file

I am trying to link a js (the js is a local file in the project) to this html (results.html) :

在此处输入图片说明

The problem is that the js is not loading .

I have try with :

/static/js/ResultspieChart.js
../static/js/ResultspieChart.js
static/js/ResultspieChart.js

But if I use:

<script th:src="@{/js/ResultspieChart.js}"></script>

it works , th is a Java template engine

In fact the url according to intelliJ helper is well formed,where is the problem ?

The file system paths are not resolved correctly most of the times. Use an http server to serve your html and ../static/js/ResultpieChart.js should work. You can use http-server npm package as below (Prerequisite: You should have node installed): 1. Install http-server globally

npm install -g http-server

  1. Start the http-server in the root of your project

http-server

This will start a server at default port (8080). So if you browse localhost:8080 , you can see your files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM