从PHP中的fetch返回捕获变量

Im try get a answer in my FETCH request:

File 1: PHP file and recived the login credential and return TRUE or FALSE:

$json_str = file_get_contents('php://input');
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "$json_str
";
fwrite($myfile, $txt);
fclose($myfile);

echo  '{ "mystatus": "TRUE" } '; //THIS IS MY VARIABLE STATUS

File 2: Send the login credentials, but in this file dont know haw can capture "mystatus"

fetch("http://xxxxxx/app/login.php", {
    method: "POST",
    mode: "same-origin",
    credentials: "same-origin",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "payload": "1234"
    })
  })

.then(function(data) {
    // Dont can capture mystatus

console.log(data);
});

How can get mystatus in File 2?

Thansk!

The initial response from the fetch api is a promise and contains a response object. You need to do something with that object. Usually its a json object so you would use the json() method to get its content.

 fetch("http://xxxxxx/app/login.php", {
    method: "POST",
    mode: "same-origin",
    credentials: "same-origin",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "payload": "1234"
    })
  })
  .then(function(response) {
      return response.json();
  }).then(function(data){
    console.lot(JSON.stringify(data);
  });

You should read the documentation. I would start here: Using Fetch | MDN()