Javascript/Ajax learner here!
I'm trying to use Ajax to load a page in a div when I click on the menu items in the navbar. I encounter several problems:
When I click the item "past" in the navbar for instance, I get the following error message in the console that refers to page I'm trying to load: "XML Parsing Error: mismatched tag. Expected: ". I can't see anything in the "past" page except for the closing head tag so I assume there's a problem in my Ajax code.
The page loads anyway, but the display of the navbar changes completely (for whatever reason).
Regarding problem 1, someone in my class suggested it might be related to an identified "response" type. But I didn't find anything that works.
Any help regarding what I have to look up is welcome. You don't have to solve my broken code. :-)
Thanks!
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">EMILIE 1, 2, 3!</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a id="past" href="#" onclick="display1()">Past</a></li>
<li class="active"><a id="present" href="#" onclick="display2()">Present</a></li>
<li class="active"><a id="future" href="#" onclick="display3()">Future</a></li>
</ul>
</div>
</nav>
<div id="container-fluid"></div>
<script>
// Past
function display1() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("container-fluid").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "past.html", true);
xhttp.send();
}
</script>
</body>