I have made the fallowing code to load various .txt files to my page, however when i use the loadPage function my .txt loads but the loading symbol on the browser keeps running which leads me to believe im doing something wrong, or not closeing the connection.
var xhr_obj;
function loadPage(file) {
alert("trying to load = "+file);
if (window.XMLHttpRequest) {
xhr_obj = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr_obj = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr_obj.onreadystatechange = tryWritePage;
xhr_obj.open("GET", file, true);
xhr_obj.send(null);
}
function tryWritePage() {
if (xhr_obj.readyState == 4) {
alert("XHR complete");
document.write(xhr_obj.responseText);
}
}
help please