AJAX XHR request onReadyStateChange events order and number of times clarification
<p>I'm learning and trying to write a simple stock quote tool using Python-Flask and Javascript.</p>

<p>I specifically want to learn <strong>plain</strong> Javascript. My code is working, but what I don't understand is when I'm watching the developer console, I get 3 error messages printed before I get the successful console.log(response). </p>

<p>Is it simply that the code loops 3 times before the response comes back, so it logged 'ERROR' each of those times before finally returning the 200 status? Would someone explain it to me or point me to a good article/post?</p>

<p>My event listener:</p>

<pre><code>document.getElementById("btn_quote").addEventListener("click", getQuote);
</code></pre>

<p>The ajax call:</p>

<pre><code>function getQuote(e){
    e.preventDefault();
    var ticker = document.getElementById("ticker").value
    var shares = document.getElementById("shares").value
    var url = "/quote/"+ticker+"/"+shares

    // Fetch the latest data.
    var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
        if (request.readyState === XMLHttpRequest.DONE) {
            if (request.status === 200) {
                var response = JSON.parse(request.response);
                console.log(response);
            }
        } else {
            // TODO, handle error when no data is available.
            console.log('ERROR');
            return false;
        }
    };
        request.open('GET', url);
        request.send();
} 
</code></pre>