I have a small script called foo.js in a folder called test where the location of the directory is unknown:
$.post("bar.php");
It's used by two different html files, one at /test/index.html:
<script src="foo.js"></script>
The other at /test/index.html:
<script src="../foo.js"></script>
When I run the script from /index.html, it works fine and bar.php is called. But when I call it from /subdirectory/index.html, javascript tells me that the resource (bar.php) can't be found. However if I copy and paste bar.php into /subdirectory, it works.
Is there a way to have javascript use the directory the script is located at (in this case, test), instead of using whatever directory it was originally called from?