fetchlogfile.html 1.5 KB
Newer Older
1 2 3
  <script>
    $(document).ready(function () {
      var lastIndex = 0;
4 5
      // The url is the same as this one with 'spewlogfile.php3' instead of
      // the current path.
6
      var url = window.location + '&isajax=1';
7 8

      // Fetch spewlogfile via AJAX call
9
      var xhr = new XMLHttpRequest();
10 11 12

      // Every time new data comes in or the state variable changes,
      // this function is invoked.
13 14
      xhr.onreadystatechange = function ()
      {
15
        // xhr.responseText contains all data received so far from spewlogfile
16 17
        if (xhr.responseText)
        {
18
          // Append only new text
19 20
          var newText = xhr.responseText.substr(lastIndex);
          lastIndex = xhr.responseText.length;
21 22 23

          // If the user is scrolled to the bottom, make sure they
          // stay scrolled to the bottom after appending.
24
          var shouldScroll = (document.body.scrollHeight - window.scrollY === window.innerHeight);
25 26 27
          $('pre').append(_.escape(newText));
          if (shouldScroll)
          {
28
            window.scroll(window.scrollX, document.body.scrollHeight);
29 30
          }
        }
31 32 33 34
	//
	// Request is done, we got everything. 
	//
	if (xhr.readyState == 4) {
Jonathon Duerig's avatar
Jonathon Duerig committed
35 36 37 38
	    //
	    // This will clear the busy indicators in the outer page,
	    // if there are any.
	    //
39 40 41 42
            if (typeof(parent.loadFinished) == "function") {
		parent.loadFinished();
	    }
	}
43
      };
44
      // Invoke the AJAX
45 46 47 48 49 50 51
      xhr.open('get', url, true);
      xhr.send();
    });
  </script>
<body>
  <pre></pre>
</body>
52