[英]jQuery .load() not loading HTML
I'm trying to make a script that imports my site's header into each page.我正在尝试制作一个脚本,将我网站的标题导入每个页面。 I have already seen these pages:
我已经看过这些页面:
I followed these sites, and I still get this error in the console:我关注了这些网站,但在控制台中仍然出现此错误:
jQuery.Deferred exception: Object doesn't support property or method 'load'
TypeError: Object doesn't support property or method 'load'
at Anonymous function (http://localhost/header-footer.js:4:5)
at l (https://code.jquery.com/jquery-3.3.1.slim.min.js:2:29559)
at Anonymous function (https://code.jquery.com/jquery-3.3.1.slim.min.js:2:29869) undefined
My index.html
has the following in the body
section:我的
index.html
在body
部分有以下内容:
<div id="header"></div>
<script src="..." integrity="..." crossorigin="anonymous"></script> <!--jQuery-->
<script src="/header-footer.js"></script> <!--Shown below-->
The header-footer.js
file includes: header-footer.js
文件包括:
$(document).ready(function () {
var header = $("#header");
header.addClass("container-fluid clearfix"); // Bootstrap classes (unrelated as far as I know)
header.load("/header.html");
});
I would just like to be able to import my header.html
file into my index.html
file.我只想能够将我的
header.html
文件导入到我的index.html
文件中。
I don't think this is related to the error, but here are the contents of my header.html
file:我不认为这与错误有关,但这里是我的
header.html
文件的内容:
<ul class="list-inline">
<li>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownButton">
<a class="dropdown-item" href="...">Another page</a>
</div>
</div>
</li>
<li><a class="btn btn-primary" href="/" role="button">Home</a></li>
<li class="lead" style="float: left;">Website Name</li>
</ul>
<hr>
What silly mistake have I made?我犯了什么愚蠢的错误? Thank you!
谢谢!
You're using jquery slim.您正在使用 jquery slim。
Use code.jquery.com/jquery-3.2.1.min.js instead of slim version to use load
method.使用 code.jquery.com/jquery-3.2.1.min.js 而不是瘦版来使用
load
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.