title: Unexpected end of JSON input although response was received
body: <p>I've written this short code to request a json file over REST from a webpage:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt;
   &lt;head&gt;
    &lt;meta charset="utf-8" /&gt;
    &lt;title&gt;&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
    &lt;button type="submit" onclick="UserAction()"&gt;Search&lt;/button&gt;
  
    &lt;script type="text/javascript" language="javascript"&gt;
    function UserAction() {
    var xhttp = new XMLHttpRequest();
    xhttp.open("POST", "http://date.jsontest.com/", true);
    xhttp.setRequestHeader("Content-type", "application/json");
    xhttp.send();
    var response = JSON.parse(xhttp.responseText);
    document.write(response);
  
    }
    &lt;/script&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However, in the java script console in chrome I get the following error: </p>
  
  <pre><code>VM33:1 Uncaught SyntaxError: Unexpected end of JSON input
  at JSON.parse (&lt;anonymous&gt;)
  at UserAction (HTMLPage1.html:17)
  at HTMLButtonElement.onclick (HTMLPage1.html:9)
  </code></pre>
  
  <p>But when I check the network response in the console, I can see the response in the following format which is correct, but it's also not displayed on the webpage:</p>
  
  <pre><code>{
     "time": "02:08:35 PM",
     "milliseconds_since_epoch": 1508767715990,
     "date": "10-23-2017"
  }
  </code></pre>
  
  <p>I have no idea what could cause this problem, does anyone know how to fix it? </p>