javascript fetch: can't get POST response data from perl script
<p>I'm trying to get a response data back from a perl CGI script:</p>

<p>I have the following JavaScript code:</p>

<pre><code>    fetch('/test.pl', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: this.state.msgName,
        email: this.state.msgEmail
      })
    })
    .then((response) =&gt; {
        console.log("been here");
        console.log(response);
    })
    .then((responseData) =&gt; {
      console.log("been here 2");
      console.log(responseData);
    })
    .then((data) =&gt; {
      console.log("been here 3");
      console.log(data);
    })
    .catch((error) =&gt; {
      console.log("Failed!", error)
    });
</code></pre>

<p>and this perl script:</p>

<pre><code>#/usr/bin/env perl
use strict;
use CGI;
use JSON;

my $q = new CGI;
my $json = new JSON;

if ($q-&gt;param)
{
  print $q-&gt;header();
  my $hash = $json-&gt;decode($q-&gt;param('POSTDATA'));
  print $q-&gt;header('application/json');
  my $msg = [ sprintf "data from %s received ok", $hash-&gt;{name} ];
  print $json-&gt;encode($msg);
}
</code></pre>

<p>but I'm only getting this (I'm using Chrome's Web Developer Tools) and no data:</p>

<pre><code> been here
 Response {type: "basic", url: "http://localhost/test.pl", status: 200, ok: true, statusText: "OK"…}
 been here 2
 undefined
 been here 3 
 undefined
</code></pre>

<p>I'm sure the perl script works ok, here's the output of testing it from the command line:</p>

<pre><code> # curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"name":"uvw","email":"xyz"}' http://localhost/test.pl
 Content-Type: application/json; charset=ISO-8859-1

 ["data from uvw received ok"]%
</code></pre>

<p>Anyone knows how to get the data response back to the js script? Thanks in advance for any help!</p>