在关闭我的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>
关于javascript - Javascript 的路径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35590654/