Get real time geojson on Javascript
First of all, readyState 4 simply means XHR is done. The response, however, can still either be a success (2xx) or a failure (4xx, 5xx). In order to distinguish a success from an error, you should also check status.

Next would be the reuse of the XHR instance. Although it's perfectly valid (open reinitializes the instance), you'll have to be absolutely sure subsequent calls aren't affected by the previous calls. It's probably much safer to just create a new instance of XHR for each request.

Then instead of window.onload, consider using addEventListener. The issue is that there might be other scripts assigning a callback to window.onload, overwriting your handler. On the other hand, multiple calls to addEventListener will just append handlers.

A simpler way to do it, assuming your target audience doesn't use legacy browsers, is fetch. It's essentially jQuery's $.ajax but natively implemented.

window.addEventListener('load', event =&gt; {
  setInterval(() =&gt; {
    fetch('data.geojson', {
      method: 'GET',
      headers: { authenticated_user: 'terrain' }
    }).then(() =&gt; {
      console.clear();
      console.log(request.response);
    })
  }, 2000)
})