How to get the root path in JavaScript?

html, javascript, jquery

Solution

What about:

$.ajax({
    type: "POST",
    url: "/login.php"
});

Make sure that you allow access to `/login.php` from your mod_rewrite rules.

Problem

I am using mod_rewrite to remap the URLs in my website in the following format: http://www.mydomain.com/health/54856 http://www.mydomain.com/economy/strategy/911025/ http://www.mydomain.com/tags/obama/new The problem is that I am making AJAX calls to a file: http://www.mydomain.com/login.php And I don't want to write the FULL url or even use the `../` trick because there isn't a fixed level of folders. So, what i want is something to access the login.php from the root, whatever the domain name is: ``` $.ajax({ type: "POST", url: "http://www.mydomain.com/login.php" }); ```

Original source