I have been working on this code with information from different online sources, but I'm stuck on the final step.
function loadajax (event) {
event.preventDefault();
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
if(xhr.status == 200)
document.ajax.dyn="Received:" + xhr.responseText;
else
document.ajax.dyn="Error code " + xhr.status;
}
};
xhr.open('GET', this.href, true);
var content = document.getElementsByTagName('article')[0];
content.innerHTML = xhr.responseText;
}
The code seems to be functioning well until it comes to adding content to my page. When I use
content.innerHTML = xhr.responseText;
, nothing is returned. I am receiving a basic HTML file - how can I display it on my page? What mistake am I making?
I appreciate any assistance you can provide!