Not getting the array from Node.js to AJAX
<p>Hi it seems based on my code that I am not reaching or responding the array from Node.js to AJAX no other errors or what not but I can not seem to figure out what is wrong with my code see below. Thank you in advance for your help!</p>

<blockquote>
  <p>AJAX code below:</p>
</blockquote>

<pre><code>function update() {
let rq = new XMLHttpRequest();
    rq.onreadystatechange = function() {
        if(rq.readyState == 4) {
        var arr = JSON.parse(rq.responseText);
        for(var i = 0; i &lt; arr.length; i++) {
        document.getElementById("message").innerHTML += "&lt;p&gt;" + arr[i] + "&lt;/p&gt;";
        }
    }
    rq.open("GET", "/messages", true);
    rq.send();
  }
}
</code></pre>

<blockquote>
  <p>Node.js code to handle GET:</p>
</blockquote>

<pre><code>if(req.method == "GET") {
  req.on('data', function(data) {
    console.log("You are reching GET-DATA");
  });
  req.on('end', function() {
    console.log("You are reching GET-END");
    res.writeHead(200, { "Content-Type" : "application/json" })
    console.log(JSON.stringify(arr))
    var toString = JSON.stringify(arr);
    res.end(JSON.stringify(arr));
  });
}
</code></pre>

<p><a href="https://i.stack.imgur.com/7e6we.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7e6we.jpg" alt="enter image description here"></a></p>

<p>I am reaching <em>console.log(req.readystate)</em> and it ouputs <em>"1"</em>, <em>alert("Your program reached rq.onreadystatechange");</em> and <em>alert("Your program reached rq.onreadystatechange = 4");</em> and then after awhile the response will now be received and I see error on the console.</p>

<p><a href="https://i.stack.imgur.com/IIzSs.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IIzSs.jpg" alt="enter image description here"></a></p>