# AJAX - page won't stop loading

**URL:** <https://forum.kirupa.com/t/ajax-page-wont-stop-loading/284479>\
**Category:** web dev\
**Created:** [March 19, 2009, 2:58pm UTC](https://forum.kirupa.com/t/ajax-page-wont-stop-loading/284479 "2009-03-19T14:58:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GrndMasterFlash](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@GrndMasterFlash](https://forum.kirupa.com/u/GrndMasterFlash)\
**Post date:** [March 19, 2009, 2:58pm UTC](https://forum.kirupa.com/t/ajax-page-wont-stop-loading/284479/1 "2009-03-19T14:58:26Z")

</div>

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.

```auto

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 😊
