'Path problem while Including a js file in several html files which are located in different folders

enter image description here

There are several html files(index.html, somewhere1.html, somewhere2.html...), and they all include same js file(script.js). And the js file(script.js) fetches a json file(data.json). The problem is, when script.js tries to fetch data.json, I cannot use same relative path(./data.json). I know I can use absolute path, but I cannot confirm where the whole folder would be located so absolute path can be changed depending on the situations.

How can I solve this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source