如何获得JavaScript的根路径? [英] How to get the root path in JavaScript?
问题描述
我使用mod_rewrite以以下格式重新映射我网站中的网址:
I am using mod_rewrite to remap the URLs in my website in the following format:
http://www.mydomain.com/economy/strategy/911025/
http://www.mydomain.com/tags/奥巴马/新
问题是我正在对文件进行AJAX调用: http://www.mydomain.com/login.php
The problem is that I am making AJAX calls to a file: http://www.mydomain.com/login.php
我不想写满FULL URL,甚至不使用 ../
技巧,因为没有固定级别的文件夹。
And I don't want to write the FULL url or even use the ../
trick because there isn't a fixed level of folders.
所以,我想要的是从根目录访问login.php,无论域名是什么:
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"
});
推荐答案
那么:
What about:
$.ajax({
type: "POST",
url: "/login.php"
});
请确保您允许访问 /login.php
from your mod_rewrite rules。
Make sure that you allow access to /login.php
from your mod_rewrite rules.
这篇关于如何获得JavaScript的根路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!