title: how to process fetch response from an 'opaque' type?
body: <p>I'm trying to correctly interpret the response from a fetch call to an URL, that I think is a json string. I've tried a many variations based on similar posts here, but nothing is getting me useful data to work with. Here is one attempt:</p>
  
  <pre><code>fetch('http://serverURL/api/ready/', {method: "POST", mode: "no-cors"})
      .then(function(response) { 
          response.json().then(function(data) {
              console.log('data:' + data);
          });
      })
      .catch(function(err) {
          console.log('Fetch Error :-S', err);
      });
  </code></pre>
  
  <p>This returns a syntax error in the console:</p>
  
  <blockquote>
    <p>SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of
    the JSON data</p>
  </blockquote>
  
  <p>So maybe its not JSON...if I put in a breakpoint on the console.log line, and hover over response (line above), I see the response object (?) with various fields:</p>
  
  <p><a href="https://i.stack.imgur.com/W9nbB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/W9nbB.png" alt="Response object from debugger hover"></a></p>
  
  <p>Not sure how to interpret that...status:0 suggests it did not get a valid response. However, if I check the Network tab in the developer tools, and click on the fetch line, status there is 200, and the Response window/JSON section shows the message info that you also see if you just put the URL into the browser URL bar directly. As does the "Response payload" section, which shows the JSON string:</p>
  
  <blockquote>
    <p>{"msg": "API is ready.", "success": true}</p>
  </blockquote>
  
  <p>So...it looks like json, no? But fetch is unable to ingest this as json?</p>
  
  <p>Here's another variation, but using response.text() instead of response.json()</p>
  
  <pre><code>fetch('http://serverURL/api/ready/', {method: "POST", mode: "no-cors"})
      .then((response) =&gt; {
          console.log(response);
          response.text().then((data) =&gt; {
              console.log("data:" + data);
      });
  });
  </code></pre>
  
  <p>This prints the response object in the console (same as above: ok: false, status:0, type:opaque etc). The second console.log file prints nothing after data:.  If I use response.json, again I get the syntax error about end of data as above.</p>
  
  <p>Any ideas? I realize the server may not be providing what fetch needs or wants, but, it does provide some info (at least when using the URL directly in the browser), which is what I need to then deal with, as json or text or whatever.</p>