1

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:

<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:

$(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.

I don't think this is related to the error, but here are the contents of my header.html file:

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

Ben Soyka
  • 816
  • 10
  • 25
  • 2
    You're using jquery slim. Is that correct? Try to use https://code.jquery.com/jquery-3.2.1.min.js instead of slim version. – Renan Araújo Nov 03 '18 at 00:10
  • 1
    Glad to hear @RenanAraújo helped. You can also see here for other differences between jQuery and jQuery slim: https://stackoverflow.com/questions/35424053 –  Nov 03 '18 at 00:13

1 Answers1

2

You're using jquery slim.

Use code.jquery.com/jquery-3.2.1.min.js instead of slim version to use load method.

Renan Araújo
  • 3,533
  • 11
  • 39
  • 49