.load()和相对路径 [英] .load() and relative paths

查看:358
本文介绍了.load()和相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.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. Here is the test case.

              有人知道我在做什么错吗?

              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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆