.load()
is giving me trouble. I'm working on a section loader project and I just can't seem to fetch the file that I need.
What I am trying to achieve:
#sectionContainer
is empty on document load, but on document ready it is 'filled' with Pages1.html
. This is done by a JavaScript file sections.js
. The JS file and the index.html are NOT in the same folder. Here is the site structure (I am running a lot of projects on my site)
And the code I use to load Pages1.html on ready:
$(document).ready(function () {
$("#sectionContainer").load("../Pages1.html", function (response, status, xhr) {
if (status == "error") {
var msg = "An error occurred. Status code: ";
$("#error").html(msg + xhr.status + ". Status text: " + xhr.statusText);
}
});
});
I have tried every possible method (/, ./, ., ../, ..) that I know of and nothing seems to work.
Does anyone know what I am doing wrong?
A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.
Relative links show the path to the file or refer to the file itself. A relative URL is useful within a site to transfer a user from point to point within the same domain. Absolute links are good when you want to send the user to a page that is outside of your server.
What is a relative path in Python? A relative path in Python is a path that describes the location of a directory relative to the entry point where you run the Python script.
An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory. Relative path is defined as the path related to the present working directly(pwd).
./Pages1.html
should work. Tested all accounts for them in the address bar.
Your AJAX URLs should be relative to the page you're on, so you want "Pages1.html"
. What you have in the test case (..Pages1.html) will never work, as that's not a valid reference. (Did you mean to do ../Pages1.html?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With