.load() 和相对路径 [英] .load() and relative paths
问题描述
.load()
给我带来了麻烦.我正在处理一个部分加载器项目,但似乎无法获取我需要的文件.
.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.
我想要达到的目标:#sectionContainer
在文档加载时为空,但在文档准备好时,它被 Pages1.html
'填充'.这是由 JavaScript 文件 sections.js
完成的.JS 文件和 index.html 不在同一个文件夹中.这是网站结构(我在我的网站上运行了很多项目)
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)
- 主文件夹
- 项目 1
- 项目 2 (sectionLoaderTest/)
- index.html
- Pages1.html
- Pages2.html
- css/
- js/
- sections.js
- main folder
- Project 1
- Project 2 (sectionLoaderTest/)
- index.html
- Pages1.html
- Pages2.html
- css/
- js/
- sections.js
以及我用来加载 Pages1.html 的代码:
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?
推荐答案
./Pages1.html
应该可以工作.在地址栏中为他们测试了所有帐户../Pages1.html
should work. Tested all accounts for them in the address bar.这篇关于.load() 和相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!