My JavaScript code is not working when the document is loaded via AJAX.
Here's the AJAX code I'm using:
var xhr;
xhr = new XMLHttpRequest();
function xhrDocOpen(doc, placeID) {
xhr.onreadystatechange=function(){
if(xhr.readyState === 4 && xhr.status === 200){
document.getElementById(placeID).innerHTML = xhr.responseText;
}
}
xhr.open('GET', doc, true);
xhr.send();
}
As you can see, this is pure JavaScript code and does not use jQuery. Some solutions I found online were using jQuery, but I prefer to solve the problem with only native JavaScript.
How can I accomplish that?