如何获得JavaScript的根路径? [英] How to get the root path in JavaScript?

查看:100
本文介绍了如何获得JavaScript的根路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mod_rewrite以以下格式重新映射我网站中的网址:

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/奥巴马/新

问题是我正在对文件进行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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆