0

Before closing the body tag of my first.php page, I want to load pop.html by javascript. Both are sitting on the root folder of my public_html directory.

By using this code:

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

It works when I access first.php directly:

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

But since I'm using a pretty URL for this page, such as:

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

pop.html won't load because of the path.

How can I load it? the weird thing is that I even tried an absolute path:

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

But even this didn't work.

Note that I need a universal solution rather than a path form that will go up only one level, as some of my pages have pretty urls that go deeper than one level.

rockyraw
  • 1,125
  • 2
  • 15
  • 36
  • 1
    Open your developer console, and report the error here... – Billy Moon Feb 23 '16 at 23:55
  • is the pretty url (`http://www.example.com/pretty/first/`) on the same domain as the original (`http://www.example.com/first.php`) url? – Billy Moon Feb 23 '16 at 23:56
  • @BillyMoon You are right, actually problem was with a path inside `pop.html`. Though since I saw [this thread ](http://stackoverflow.com/questions/2188218/relative-paths-in-javascript-in-an-external-file) I thought maybe my problem was related to that case. – rockyraw Feb 24 '16 at 00:02

1 Answers1

2

Best solution is probably an absolute path with no scheme or domain part:

<script type="text/javascript">
$( "#modal-layer" ).load( "/pop.html" );
</script>
Matti Virkkunen
  • 63,558
  • 9
  • 127
  • 159