Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

jquery - .load() and relative paths

.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)

  • main folder
  • Project 1
  • Project 2 (sectionLoaderTest/)
    • index.html
    • Pages1.html
    • Pages2.html
    • css/
    • js/
      • sections.js
  • Project 3
  • ...

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

./Pages1.html should work. Tested all accounts for them in the address bar.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...