Javascript 的路径不起作用

Paths with Javascript not working

在关闭 first.php 页面的 body 标签之前,我想通过 javascript 加载 pop.html。两者都位于我的 public_html 目录的根文件夹中。

通过使用此代码:

<script type="text/javascript">
$( "#modal-layer" ).load( "pop.html" );
</script>

当我直接访问 first.php 时有效:

http://www.example.com/first.php

但是因为我为这个页面使用了漂亮的 URL,例如:

http://www.example.com/pretty/first/

pop.html 由于路径原因无法加载。

如何加载它?奇怪的是我什至尝试了绝对路径:

<script type="text/javascript">
$( "#modal-layer" ).load( "http://www.example.com/pop.html" );
</script>

但即使这样也行不通。

请注意,我需要一个通用的解决方案,而不是只能向上一级的路径形式,因为我的一些页面具有比一级更深的漂亮网址。

最佳解决方案可能是没有方案或域部分的绝对路径:

<script type="text/javascript">
$( "#modal-layer" ).load( "/pop.html" );
</script>