<p>I have some code in a javascript file that needs to send queries back to the server. The question is, how do I find the url for the script that I am in, so I can build a proper request url for ajax.</p>

<p>I.e., the same script is included on <code>/</code>, <code>/help</code>, <code>/whatever</code>, and so on, while it will always need to request from <code>/data.json</code>. Additionally, the same site is run on different servers, where the <code>/</code>-folder might be placed differently. I have means to resolve the relative url where I include the Javascript (ez-publish template), but not within the javascript file itself.</p>

<p>Are there small scripts that will work on all browsers made for this?</p>

```
document.location.href
```
will give you the current URL, which you can then manipulate using JavaScript's string functions.